Created
October 30, 2014 00:17
-
-
Save aral/f208f7408e56b6db19d7 to your computer and use it in GitHub Desktop.
Hash Sieve in CoffeeScript
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
# | |
# Implementation of hash sieve algorithm that I read | |
# about at http://www.shamasis.net/2009/09/fast-algorithm-to-find-unique-items-in-javascript-array/ | |
# in CoffeeScript with slightly more literate code :) | |
# | |
Array.prototype.unique = -> | |
hashSieve = {} | |
arrayOfUniqueValues = []; | |
for item in @ | |
hashSieve[item] = item | |
for item of hashSieve | |
arrayOfUniqueValues.push item | |
return arrayOfUniqueValues | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
(For quickly reducing an array to unique values.)