Created
December 23, 2016 16:20
-
-
Save railsstudent/230b76b48628be47639adaa29b5a8c92 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Array.prototype.sameStructureAs = function (other) { | |
// Return 'true' if and only if 'other' has the same | |
// nesting structure as 'this'. | |
// Note: You are given a function isArray(o) that returns | |
// whether its argument is an array. | |
if (this.length !== other.length) { | |
return false; | |
} | |
for (var i = 0; i < this.length; i++) { | |
if (isArray(this[i]) && isArray(other[i])) { | |
if (!this[i].sameStructureAs(other[i])) { return false; } | |
} else if (!isArray(this[i]) && isArray(other[i])) { | |
return false; | |
} else if (isArray(this[i]) && !isArray(other[i])) { | |
return false; | |
} | |
} | |
return true | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
great !