Created
November 1, 2017 21:04
-
-
Save bcls/b575aa4569f66627d395d62a777e016a to your computer and use it in GitHub Desktop.
dedupe simple array #javascript
This file contains 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
/** | |
* dedupe a simple array of strings or numbers | |
* @param {array} arr the array to be deduped | |
* @return {array} out the deduped array | |
*/ | |
function dedupe(arr) { | |
var i, | |
len = arr.length, | |
out = [], | |
obj = {}; | |
for (i = 0;i < len; i++) { | |
obj[arr[i]] = 0; | |
} | |
for (i in obj) { | |
out.push(i); | |
} | |
return out; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment