Given a set of closed intervals, find the smallest set of numbers that covers all the intervals The Task:


  Given a set of closed intervals, find the smallest set of numbers that
  covers all the intervals. If there are multiple smallest sets, return
  any of them.
  
  For example, given the intervals [0, 3], [2, 6], [3, 4], [6, 9], one
  set of numbers that covers all these intervals is {3, 6}.


My solution:

const intervalls = [[0, 3], [2, 6], [3, 4], [6, 9]];
const getLargestMinAndSmallestMax = (acc, intervall, _, src) =&gt; {
    if (src.length === 0) { return []; }
    if (src.length === 1) { return intervall; }
    if (acc[1] === undefined || intervall[0] &gt; acc[1]) {
      acc[1] = intervall[0];
    }
    if (acc[0] === undefined || intervall[1] &lt; acc[0]) {
      acc[0] = intervall[1];
    }
    return acc;
  };
const smallestIntervallCoveringAllIntervalls = list =&gt; list.reduce(getLargestMinAndSmallestMax, []);

console.log(smallestIntervallCoveringAllIntervalls(intervalls));


Is there a faster and cleaner version of it?
Naming
First point is that I think the naming is getting a little verbose smallestIntervallCoveringAllIntervalls and getLargestMinAndSmallestMax

getLargestMinAndSmallestMax get largest min and smallest max, don't you mean get &quot;range&quot;? And its not get, the range is not known, you need to &quot;find&quot; it. findRange

smallestIntervallCoveringAllIntervalls This is when comments come into play. If you were part of a team that functions name would already be defined in the interface spec. However if it was an internal call (your code) you would use a smaller name and add a comment to give it the missing meaning as a reminder to you, or for someone that may later need to modify your code.


Spelling
intervalls should be intervals
Bad spelling is a gateway to bug hell. Others can not guess how you have misspelled a name, so always check if you are unsure as to the spelling of a name.
The spec
No project starts without a detailed specification regarding the problem. Part of a programmers job is to ensure that the spec is unambiguous.
If you have any questions that the spec can not answer then you should not start working on a solution. Rather a memo to the team leader, or email to the client with the points that need to be resolved.
So lets restate the problem

Given an array of intervals find the smallest interval that covers all intervals.

The intervals array will always contain one or more valid intervals.

An interval is covering another interval if one or more values in its range are the same. Examples A = [0, 1], B = [1, 2], C = [3, 4]. A covers B, C does not cover A and B

An interval is an array containing two unsorted integers, that have a range from min to max value inclusive. Examples [0, 1] has a range 0, 1. [3, -2] has a range  -2, -1, 0, 1, 2, 3. [2, 2] has a range 2.
The following [], [0], [1,2,3] are not valid intervals

The return must be a valid interval


Your code
You have a bug and return incorrect intervals in some cases.
Two examples of the bug

Given  the intervals [[10, 20], [10, -20]] your function returns [-20,10] which is in fact the largest range, the correct solution is [10, 10] (Yes unfair as [10,-20] is A over T)

Given intervals [[10,20]] you incorrectly return [10,20]. There are 11 possible correct solutions. Any of  [10,10], [11, 11], ..., [n, n] (n = 20)


The reason you are returning incorrect intervals is that you do not treat the first interval correctly, as shown in the second example above.
When finding min and max values of a set of anything with at least one item, you always treat the first item differently. The first items initializes the min or max.
You use Array.reduce so that means you need to include a test to see if you have the first interval.
The interval that covers a single interval always has a range length of one and is any of the values in the intervals range. eg [[10,20]] is covered by [10,10] or [20,20]
Fix using your logic
// int for interval
const smallestRange = (res, int) =&gt; {
    if (res.length === 0) {  return [int[0], int[0]] }
    if (int[0] &gt; res[1]) { res[1] = int[0] }
    if (int[1] &lt; res[0]) { res[0] = int[1] }
    return res;
};
const findSmallestRange = ints =&gt; ints.reduce(smallestRange , []);

If we now solve to include intervals that are backward (the other question said use Array.sort. NEVER! use sort for a two item array, in fact you only use sort if you can find no other way to sort any items)
Solve new spec
Solution using while loop and to spec outlined above.
Note that I use lowIdx + 1 &amp; 1 as it is slightly faster than (lowIdx + 1) % 2. This is not a micro optimization, this is a known optimization, when all things equal always use the fastest method. (also note that % has lower precedence than + so requires the ()
Using Math.min and Math.max
&quot;use strict&quot;;
// Renamed interval to set
function findCoveringInterval(sets) { // finds smallest 
    var i = 0, min = sets[i][0], max = min;
    while (++i  &lt; sets.length) { // must be ++i not i++
        const set = sets[i], lowIdx = set[0] &lt; set[1] ? 0 : 1;
        max = Math.max(set[lowIdx], max); 
        min = Math.min(set[lowIdx + 1 &amp; 1], min);
    }
    return [max, min];
}

I prefer using ternary min max because Math.min/max has additional overhead checking against the length of its argument array. However this makes the function longer so it counts as a micro optimization. (I would need to test performances as I add JS complexity competing against native complexity)
&quot;use strict&quot;;
function findCoveringInterval(sets) {
    var i = 0, min = sets[i][0], max = min;
    while (++i &lt; sets.length) {
        const set = sets[i];
        let idx = set[0] &lt; set[1] ? 0 : 1;
        max = set[idx] &gt; max ? set[idx++] : (idx++, max); 
        min = set[idx &amp;= 1] &lt; min ? set[first] : min;
    }
    return [max, min];
}