Smallest job first algorithm implementation
I think this can be done with far less code. Like this:

function calculateTotalClockCycles(jobs, index) {
  jobs.sort((a, b) =&gt; a - b);
  return jobs.slice(0, index).reduce((a, b) =&gt; a + b, 0);
}

alert(calculateTotalClockCycles([10, 3, 15, 8, 7], 3));


In the first line of code inside the function, the jobs are sorted, small to large. The second line is more complicated. The reduce() method is used to sum all the values of the array it applies to. That array is the wanted part (slice) of the whole sorted jobs array.

So here reduce() is used as an alternative for a 'for' loop.