Last active
December 28, 2015 18:49
-
-
Save ramntry/7545613 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
var arr = []; | |
for (var i = 0, l = 100*1000; i < l; i++) { | |
arr.push(Math.round(Math.random() * l)) | |
} | |
Array.prototype.diff = function(a) { | |
return this.filter(function(i) {return !(a.indexOf(i) > -1);}); | |
}; | |
for (var i = 0; i < 10; ++i) { | |
console.log(arr.diff(arr).length == 0); | |
} |
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
var arr = []; | |
for (var i = 0, l = 100*1000; i < l; i++) { | |
arr.push(Math.round(Math.random() * l)) | |
} | |
Array.prototype.hasAll = function(a) { | |
var hash = this.reduce(function(acc, i) { acc[i] = true; return acc; }, {}); | |
return a.every(function(i) { return i in hash; }); | |
}; | |
for (var i = 0; i < 10; ++i) { | |
console.log(arr.hasAll(arr)); | |
} |
Author
ramntry
commented
Nov 19, 2013
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment