Nodejs Array Unique unique(a)

Here you can find the source of unique(a)

Method Source Code

x = ''/*w  ww  .  j a va2s  .  c  o  m*/
Array.prototype.unique=function(a){
  return function(){return this.filter(a)}}(function(a,b,c){return c.indexOf(a,b+1)<0
});
// n = letters, r = cant, res = string

function getCombi(vect,res,n,r){
   if(n == 0){
      x = x + res +":";
   }else{
      for(var i = 0; i < r; i++){
          getCombi(vect,res + vect[i], n-1,r);
      }
   }
}
line = "1,a";
v = line.split(",")[1].split("");
n = v.length;
r = parseInt(line.split(",")[0]);
getCombi(v,'',n,r);
console.log(x.substring(0,x.length-1).split(":").unique().join(","));

Related

  1. unique()
    Array.prototype.unique = function(){
      this.sort((x,y) => x-y);
      for(var i=0; i<this.length-1; ){
        if(this[i]==this[i+1])
          this.splice(i,1);
        else i++;
      return this;
    
  2. unique()
    Array.prototype.unique = function() 
        var h = {};  
        var r = [];
        this.forEach(function (item) { h[item] = true; });
        for (var item in h)
            r.push(item);
        return r; 
    
  3. unique()
    Array.prototype.unique = function() {
      var uniqueArray = new Array();
      for(var i = 0; i < this.length; i++) {
        for(var j = i+1; j < this.length+1; j++) {
          if (this[i] !== null && this[i] === this[j]) 
            this[j] = null;
      for(i = 0; i < this.length; i++) {
    ...
    
  4. unique(a)
    Array.prototype.unique=function(a){
      return function(){return this.filter(a)}}(function(a,b,c){return c.indexOf(a,b+1)<0
    });
    
  5. unique(a)
    Array.prototype.unique = function(a) {
        return function(){return this.filter(a)}}(function(a,b,c){return c.indexOf(a,b+1)<0
    });
    
  6. unique(a)
    Array.prototype.unique = function(a) {
        return function(){return this.filter(a)}}(function(a,b,c){return c.indexOf(a,b+1)<0
    });
    
  7. unique(b)
    Array.prototype.unique = function(b) {
        var a = [], i, l = this.length;
        for (i = 0; i < l; i++) {
            if (a.indexOf(this[i], 0, b) < 0) {
                a.push(this[i]);
        return a;
    };
    ...
    
  8. unique(b)
    Array.prototype.unique = function(b) {
      var a = [], i, l = this.length;
      for (i = 0; i < l; i++) {
        if (a.indexOf(this[i], 0, b) < 0) {
          a.push(this[i]);
      return a;
    };
    ...
    
  9. unique(callback)
    Array.prototype.unique = function(callback) {
      var o = {}, i, l = this.length, r = [];
      for (i=0; i<l; i+=1) {
        var val = callback(this[i]);
        o[val] = this[i];
      for (i in o) {
        r.push(o[i]);
      return r;
    };