Skip to content

Instantly share code, notes, and snippets.

@fupslot
Created October 29, 2015 13:44
Show Gist options
  • Save fupslot/1af4b22a84604bd18f09 to your computer and use it in GitHub Desktop.
Save fupslot/1af4b22a84604bd18f09 to your computer and use it in GitHub Desktop.
javascript, unique, uniq, filtering
function unique(in_list) {
var lookup = {};
var values = [];
for (var i = 0; i < in_list.length; i++) {
if (!lookup[in_list[i]]) {
values.push(in_list[i]);
}
lookup[in_list[i]] = true;
}
return values;
};
@fupslot
Copy link
Author

fupslot commented Oct 29, 2015

console.log(unique([1, 4, 1, 2, 3, 4, 3, 2])); //->  [1, 4, 2, 3 ]
 Note: Not really suites for big arrays.

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