Nodejs Array Equal Check isEqual(arr)

Here you can find the source of isEqual(arr)

Method Source Code

const a = [1, 2, 3];/*  ww  w. ja  va2  s.  co m*/
const b = [1, 2, 3];

Array.prototype.isEqual = function (arr) {

   function check(arr1, arr2) {
      for (let i = 0, len = arr1.length; i < len; i++) {
         const bool = arr2.some(function (item) {
            return Object.is(arr1[i], item);
         });
         if (!bool) return false;
      }
      return true;
   }

   return check(this, arr) && check(arr, this);
};


console.log(a.isEqual(b));

Related

  1. isEqual(a)
    Array.prototype.isEqual = function(a){
      if(this.length!=a.length) return false;
      for(var i=0;i<this.length;i++){
        if(this[i] instanceof Array){
          if(!(a[i] instanceof Array)) return false;
          if(!this[i].isEqual(a[i])) return false;
        }else{
          if(this[i]!=a[i]) return false;
      return true;
    
  2. isEqual(target)
    "use strict";
    Array.prototype.isEqual = function(target){
      if (this == target) return true;
      if (this == null || target == null) return false;
      if (this.length != target.length) return false;
      for(var i in this){
        if (
          (this[i] !== target[i]) &&
          (typeof this[i].isEqual != "function" ||
    ...