Skip to content

Instantly share code, notes, and snippets.

@aral
Created October 30, 2014 00:17
Show Gist options
  • Save aral/f208f7408e56b6db19d7 to your computer and use it in GitHub Desktop.
Save aral/f208f7408e56b6db19d7 to your computer and use it in GitHub Desktop.
Hash Sieve in CoffeeScript
#
# 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
@aral
Copy link
Author

aral commented Oct 30, 2014

(For quickly reducing an array to unique values.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment