Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save lwebber/43e101feddcd6f79c94261e1b0dadf8b to your computer and use it in GitHub Desktop.
Save lwebber/43e101feddcd6f79c94261e1b0dadf8b to your computer and use it in GitHub Desktop.
Third Greatest with Sort(compare) created by wwebby1 - https://repl.it/E876/3
// # Write a method that takes an array of numbers in. Your method should
// # return the third greatest number in the array. You may assume that
// # the array has at least three numbers in it.
// #
function thirdGreatest(nums){
nums.sort(function compare(num1, num2)
{return num1 -num2});
return nums[nums.length-3];
}
console.log(thirdGreatest([4,6,1,3,8,3,4]));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment