• + 0 comments

    another solution

    nums.sort(function(a, b){return a-b});
    let secLargest = nums[nums.length-2];
    let largest = nums[nums.length-1];
    for (let i = nums.length-1; i >= 0; i--){
    if(nums[i-1] == nums[i]) {
        largest = nums[i-1];
        secLargest = nums[i-2];
    } else {
        secLargest = nums[i-1];
        break;
    }
    }
    return secLargest;
    

    }