Forked from anonymous/Third Greatest with Sort(compare).js
Created
December 3, 2016 08:11
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// # 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