Javascript Array isEqual(arr)

Description

Javascript Array isEqual(arr)



const a = [1, 2, 3];//  w w  w  .j a va2  s  .  com
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));



PreviousNext

Related