Skip to content

Instantly share code, notes, and snippets.

@zerosum
Last active April 23, 2017 10:57
Show Gist options
  • Save zerosum/87d6340743f9c9bb0cd0a2cbbaaf6b0d to your computer and use it in GitHub Desktop.
Save zerosum/87d6340743f9c9bb0cd0a2cbbaaf6b0d to your computer and use it in GitHub Desktop.
Array.prototype.filterNot = function (callback) {
var result = [];
for (e of this) {
if (!callback(e)) {
result.push(e);
}
};
return result;
}
Array.prototype.distinct = function (callback) {
var result = [];
var rec = function(next) {
if (next.length === 0) {
return result;
} else {
var head = next[0];
var left = next.filterNot(callback.bind(null, head));
result.push(head)
return rec(left)
}
};
return rec(this);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment