Skip to content

Instantly share code, notes, and snippets.

@bsimpson
Created April 20, 2017 16:38
Show Gist options
  • Save bsimpson/b5ba37b7b9261d6cbe362e37771f70af to your computer and use it in GitHub Desktop.
Save bsimpson/b5ba37b7b9261d6cbe362e37771f70af to your computer and use it in GitHub Desktop.
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