Last active
August 29, 2015 14:24
-
-
Save markjanzer/bf6b18108e5f8fa06607 to your computer and use it in GitHub Desktop.
SecondHighLow
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
function SecondGreatLow(arr) { | |
arr = arr.sort(function (a, b) {return a - b}); | |
return secondLow(arr) + " " + secondHigh(arr); | |
} | |
function secondLow(arr) { | |
for (var i = 0; i < arr.length; i++) | |
if (arr[i] !== arr[i +1]) | |
return (arr[i + 1]); | |
} | |
function secondHigh(arr) { | |
for (var i = arr.length - 1; i > 0; i--) | |
if (arr[i] !== arr[i - 1]) | |
return (arr[i - 1]); | |
} | |
console.log(SecondGreatLow([1, 42, 42, 180])); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
So this code does not work, but when I add a semicolon to the end of line 14 it does work. I can't figure out why.