Skip to content

Instantly share code, notes, and snippets.

Created December 3, 2016 08:10
Show Gist options
  • Save anonymous/7e64476088ca05e5c9390a1595a56fac to your computer and use it in GitHub Desktop.
Save anonymous/7e64476088ca05e5c9390a1595a56fac 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