Last active
April 23, 2017 10:57
-
-
Save zerosum/87d6340743f9c9bb0cd0a2cbbaaf6b0d to your computer and use it in GitHub Desktop.
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
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