Skip to content

Instantly share code, notes, and snippets.

@rjmacarthy
Created April 21, 2016 14:41
Show Gist options
  • Save rjmacarthy/28b83be9e0e653b72532ed9dfbc86912 to your computer and use it in GitHub Desktop.
Save rjmacarthy/28b83be9e0e653b72532ed9dfbc86912 to your computer and use it in GitHub Desktop.
Find a unique item in an array.
var orig = [1,1,2,2,3,3,4];
var result;
orig.forEach(function(num, i){
var test = orig.slice(0);
test.splice(i, 1)
if(test.indexOf(num) === -1){
result = num;
}
});
return result; // 4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment