Created
April 20, 2017 16:38
-
-
Save bsimpson/b5ba37b7b9261d6cbe362e37771f70af to your computer and use it in GitHub Desktop.
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
const array = [1,2,3,4,4]; | |
function findDuplicate(inArr) { | |
inArr.reduce((sum, entity, idx) => { | |
sum[entity] = true; | |
if (Object.keys(sum).length != idx+1) { | |
throw `Duplicate found at index ${idx} in value ${entity}`; | |
} | |
return sum; | |
}, {}); | |
} | |
findDuplicate(array); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment