Ad
  • Custom User Avatar

    Not so good.
    Because sort giving O(n) log n complexity of the algorithm.
    You can solve it with linear complexity.
    For exemple:

    function twoOldestAges(ages){
    var max = 0;
    var secMax = 0;

    for (i = 0; i<ages.length ; i++){
        if(ages[i] > max){
            max = ages[i];
        }else if(ages[i] > secMax){
            secMax = ages[i];
        }
    }
    return [secMax, max];
    

    }

  • Custom User Avatar

    It's the optimal way of solving this kata.