Last active
June 28, 2016 06:36
-
-
Save avishwakarma/2f8a929d0314349f6005227603833598 to your computer and use it in GitHub Desktop.
JavaScript Array function for unique elements
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
/** | |
* unique - Array function for unique elements | |
* @use [2, 2, 3, 4, 3, 2].unqiue() // [2, 3, 4] | |
*/ | |
Array.prototype.unique = function() { | |
var unique = []; | |
for (var i = 0; i < this.length; i++) { | |
if (unique.indexOf(this[i]) == -1) { | |
unique.push(this[i]); | |
} | |
} | |
return unique; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment