Skip to content

Instantly share code, notes, and snippets.

@markjanzer
Last active August 29, 2015 14:24
Show Gist options
  • Save markjanzer/bf6b18108e5f8fa06607 to your computer and use it in GitHub Desktop.
Save markjanzer/bf6b18108e5f8fa06607 to your computer and use it in GitHub Desktop.
SecondHighLow
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]));
@markjanzer
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment