Created
April 21, 2016 14:41
-
-
Save rjmacarthy/28b83be9e0e653b72532ed9dfbc86912 to your computer and use it in GitHub Desktop.
Find a unique item in an 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
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