Created
February 1, 2016 17:16
-
-
Save giannispan/20b483cb7c6f6a643fdd to your computer and use it in GitHub Desktop.
Find The Parity Outlier
This file contains hidden or 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 findOutlier(integers){ | |
var length = integers.length, i; | |
var evens = []; | |
var odds = []; | |
var k | |
for (i=0; i<length; i++) { | |
if (integers[i] % 2 == 0) { | |
evens.push(integers[i]); | |
} | |
if (Math.abs(integers[i] % 2) == 1) { | |
odds.push(integers[i]); | |
} | |
} | |
if (evens.length > odds.length) | |
return odds[0]; | |
else | |
return evens[0]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment