Last active
January 12, 2016 22:35
-
-
Save brianswisher/7ed8f8d9867da086a901 to your computer and use it in GitHub Desktop.
Get Bachelor - return odd occurrence in array
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(input){ | |
function solution(A){ | |
var input = (function(bachelor){ | |
if (typeof A !== "object") throw new Error("A is not an object."); | |
if (typeof A.split === "function") throw new Error("A is not an array."); | |
if (!(A.length % 2)) throw new Error("A.length even."); | |
return { | |
squashCouples: function(lookup){ | |
lookup = {}; | |
A.map(function(val){ | |
val = val.toString(); | |
if (!lookup[val]){ | |
lookup[val] = true; | |
} else { | |
delete(lookup[val]); | |
} | |
}); | |
A = lookup; | |
return this; | |
}, | |
getBachelor: function(){ | |
return parseInt(Object.keys(A).pop()); | |
} | |
}; | |
})(); | |
return input | |
.squashCouples() | |
.getBachelor(); | |
} | |
return solution(input); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment