Javascript Array unique(a)
var a = [//from w ww .ja v a 2s.co m [0, 0, 0, 0, 0], [1, 0, 0, 1, 1], [1, 1, 1, 1, 1] ]; Array.prototype.unique=function(a){ return function(){return this.filter(a)}}(function(a,b,c){return c.indexOf(a,b+1)<0 }); console.log(a[2].unique()); console.log(a);
Array.prototype.unique = function (a) { return function () { return this.filter(a); }; }(function (a, b, c) { return c.indexOf(a, b + 1) < 0; });//from www . j av a 2 s . c o m
/**/*from w ww . j a va 2 s. c o m*/ * This file contains prototype extensions for default javascript handlers */ /** * Array unique for javascript array. * * @type {Array.prototype.unique} * * @returns {array} */ Array.prototype.unique = function(a) { return function(){return this.filter(a)}}(function(a,b,c){return c.indexOf(a,b+1)<0 });
Array.prototype.unique = function(a){ return function(){ return this.filter(a) } }(function(a,b,c){ return c.indexOf(a,b+1) < 0 }); var num = 0;//from w w w . j a v a 2 s. c o m var uniqs2 =1000; require('fs').readFileSync('8.txt').toString().split('\n').forEach(function (line) { var arr = []; for(i=0;i<line.length/32;i++){ arr.push(line.substring(i*32, i*32+31)) } num++; uniqs1=arr.unique().length; if(uniqs1<uniqs2){numf=num;uniqs2=uniqs1;} //console.log('Linia:'+num+' '+arr.unique().length) }) console.log('Linia:'+numf)