You are viewing a single comment's thread. Return to all 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;
}
Seems like cookies are disabled on this browser, please enable them to open this website
Day 3: Arrays
You are viewing a single comment's thread. Return to all comments →
another solution
}