Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Array.prototype.unique = function(a){
- return function(){return this.filter(a)}}(function(a,b,c){return c.indexOf(a,b+1)<0
- });
- Benchmark.prototype.setup = function() {
- Array.prototype.contains = function(v) {
- for(var i = 0; i < this.length; i++) {
- if(this[i] === v) return true;
- }
- return false;
- };
- Array.prototype.unique = function() {
- var arr = [];
- for(var i = 0; i < this.length; i++) {
- if(!arr.contains(this[i])) {
- arr.push(this[i]);
- }
- }
- return arr;
- }
- //if you need a 'shim':
- Array.prototype.filter= Array.prototype.filter || function(fun, scope){
- var T= this, A= [], i= 0, itm, L= T.length;
- if(typeof fun== 'function'){
- while(i<L){
- if(i in T){
- itm= T[i];
- if(fun.call(scope, itm, i, T)) A[A.length]= itm;
- }
- ++i;
- }
- }
- return A;
- }
- Array.prototype.indexOf= Array.prototype.indexOf || function(what, i){
- if(!i || typeof i!= 'number') i= 0;
- var L= this.length;
- while(i<L){
- if(this[i]=== what) return i;
- ++i;
- }
- return -1;
- }
- var duplicates = [1,3,4,2,1,2,3,8];
- // kodono.info
- Array.prototype.unique2=function(){var o={},i,l=this.length,r=[];for(i=0;i<l;i++)o[this[i]]=this[i];for(i in o)r.push(o[i]);return r}
- };
- var unique= array1.filter(function(itm, i){
- return array1.indexOf(itm)== i;
- // returns true for only the first instance of itm
- });
- //if you need a 'shim':
- Array.prototype.filter= Array.prototype.filter || function(fun, scope){
- var T= this, A= [], i= 0, itm, L= T.length;
- if(typeof fun== 'function'){
- while(i<L){
- if(i in T){
- itm= T[i];
- if(fun.call(scope, itm, i, T)) A[A.length]= itm;
- }
- ++i;
- }
- }
- return A;
- }
- Array.prototype.indexOf= Array.prototype.indexOf || function(what, i){
- if(!i || typeof i!= 'number') i= 0;
- var L= this.length;
- while(i<L){
- if(this[i]=== what) return i;
- ++i;
- }
- return -1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement