Nodejs Array Unique uniq()

Here you can find the source of uniq()

Method Source Code

Array.prototype.uniq = function () {

  var uniq_arr = [];

  for (var i = 0; i < this.length; i++) {

    var included = false;

    for (var j = 0; j < uniq_arr.length; j++) {

      if (uniq_arr[j] === this[i]) {
        included = true;/*from w ww. j a va2  s .  c om*/
        break;
      };
    };

    if (included === false) {
      uniq_arr.push(this[i]);
    };
  };

  return uniq_arr;
};


Array.prototype.twoSum = function () {

  var sum_arr = [];

  for (var i = 0; i < this.length; i++) {

    for (var j = i+1; j < this.length; j++) {
      if ((this[i] + this[j]) === 0) {
        sum_arr.push([i,j]);
      };
    };
  };

  return sum_arr;

};


var transpose = function(matrix) {

  var transposed = [];

  for (var i = 0; i < matrix.length; i++) {
    var column = [];

    for (var j = 0; j < matrix[i].length; j++) {
      column.push(matrix[j][i]);
    };

    transposed.push(column);
  };
  return transposed;
};

Related

  1. uniq()
    Array.prototype.uniq = function () {
      var results = [];
      for (var i = 0; i < this.length; i++) {
        var includes = false;
        for (var j = 0; j < results.length; j++) {
          if (results[j] === this[i]) {
            includes = true;
        };
    ...
    
  2. uniq()
    Array.prototype.uniq = function ()
      var dups = [];
      for (var i = 0; i < this.length; i++)
        var flag = true;
        for (var j = 0; j < dups.length; j++)
          if (this[i] === dups[j])
    ...
    
  3. uniq()
    Array.prototype.uniq = function () {
        var flag = false;
        var result = [];
        for(var i=0;i<this.length;i++) {
            if(result.indexOf(this[i]) == -1) {
                if(this[i]==this[i]) {
                    result.push(this[i]);
                else if(!flag) {
    ...
    
  4. uniq()
    Array.prototype.uniq = function(){
      var uniqArray = [];
      for (var i = 0; i < this.length; i++){
        if (uniqArray.indexOf(this[i]) === -1)
          uniqArray.push(this[i])
      return uniqArray
    ...
    
  5. uniq()
    Array.prototype.uniq = function() {  
        var temp = {};
        for(var i=0; i<this.length; i++)  {  
                temp[this[i]] = 1;
        this.length = 0;
        for(var e in temp) {  
            this.push(e);
        this.sort()
        return this;  
    function xmlencode(string) {
        return string.replace(/\&/g,'&'+'amp;').replace(/</g,'&'+'lt;')
            .replace(/>/g,'&'+'gt;').replace(/\'/g,'&'+'apos;').replace(/\"/g,'&'+'quot;');
    
  6. uniq()
    Array.prototype.uniq = function() {
      let res = [];
      for(let i=0; i < this.length; i++) {
        let value = this[i];
        if (!res.includes(value)) res.push(value);
      return res;
    };
    console.log([1,2,2,1,1,3].uniq());
    ...
    
  7. uniq()
    Array.prototype.uniq = function () {
      var uniqueArray = [];
      for (var i = 0; i < this.length; i++) {
        if (uniqueArray.indexOf(this[i]) === -1) {
          uniqueArray.push(this[i]);
      return uniqueArray;
    };
    ...
    
  8. uniq()
    "use strict";
    Array.prototype.uniq = function () {
      let uniqueArray = [];
      for (let i = 0; i < this.length; i++) {
        if (uniqueArray.indexOf(this[i]) === -1) {
          uniqueArray.push(this[i]);
      return uniqueArray;
    ...
    
  9. uniq()
    Array.prototype.uniq = function () {
      var newArray = [];
      for (var i = 0; i < this.length; i++) {
        var el = this[i];
        if (newArray.indexOf(el) === -1) {
          newArray.push(el);
      return newArray;
    ...