JSFiddle - React, Tailwind, and code Playground

by hescano

JavaScript

Array.prototype.sameStructureAs = function (other) {
	return sameStructureAs(this, other);
};

function sameStructureAs(arr1, arr2) {
	if (arr1.length === arr2.length && isArray(arr1) && isArray(arr2)) {
  	arr1 = arr1.pop();
  	arr2 = arr2.pop();
    return sameStructureAs(arr1, arr2);
  } else if (isArray(arr1) && isArray(arr2) && arr1.length !== arr2.length) {
  	return false;
  } else {
  	return true;
  }
  
  return false
}


 function isArray(arg) {
    return Object.prototype.toString.call(arg) === '[object Array]';
  }

console.log([1,[1,1]].sameStructureAs([2,[2]]));