List of utility methods to do Array Same Structure
sameStructureAs(a2)Array.prototype.sameStructureAs = function(a2) { let isSame = true; (function recurse(arr1, arr2){ if (!arr1 || !arr2) { isSame = false; return; if (arr1.length !== arr2.length) { isSame = false; ... | |
sameStructureAs(other)Array.prototype.sameStructureAs = function (other) { const stringify = a => `[${a.map(b => Array.isArray(b) ? stringify(b) : '|').join('')}]` return Array.isArray(other) ? stringify(this) === stringify(other) : false | |
sameStructureAs(other)Array.prototype.sameStructureAs = function (other) { if ( this.length !== other.length ) return false; for ( var i = 0; i < this.length; i++ ){ if (Array.isArray(this[i]) && Array.isArray(other[i])) { if (!this[i].sameStructureAs(other[i])) return false; } else if (Array.isArray(this[i]) || Array.isArray(other[i])){ return false; return true; }; | |
sameStructureAs(other)Array.prototype.sameStructureAs = function (other) { var helper = function(a,b){ if(!isArray(b)) return false; for(i in a){ if(b[i]===undefined || isArray(a[i])!==isArray(b[i]) || isArray(a[i]) && !a[i].sameStructureAs(b[i])) return false; return true; ... | |
sameStructureAs(other)Array.prototype.sameStructureAs = function (other) { if (!Array.isArray(other)) return false; function transform(array) { return array.map(item => Array.isArray(item) ? [transform(item)] : "0"); return JSON.stringify(transform(this)) === JSON.stringify(transform(other)); }; console.log([ 1, [ 1, 1 ] ].sameStructureAs( [ 2, [ 2, 2 ] ] )); console.log([ [ [ ], [ ] ] ].sameStructureAs( [ [ [ ], [ ] ] ] )) ... | |
sameStructureAs(other)Array.prototype.sameStructureAs = function(other) { if (Array.isArray(other) === false) { return false; return compareArrays(this, other); }; function compareArrays(arr1, arr2) { if (arr1.length !== arr2.length) { return false; ... | |
sameStructureAs(other)Array.prototype.sameStructureAs = function (other) { return this && other && Array.isArray(this) === Array.isArray(other) && this.every(function(element, i) { if (Array.isArray(element)) { return element.sameStructureAs(other[i]); return element && other[i] && Array.isArray(element) === Array.isArray(other[i]); }); }; | |
sameStructureAs(other)Array.prototype.sameStructureAs = function (other) { if(other.constructor !== Array){ return false; } else { emptyNested(this); emptyNested(other); var arr1Str = JSON.stringify(this); var res1 = ''; var arr2Str = JSON.stringify(other); ... |