michael@0: // A for-of loop over an array stops at the new end of the array if it shrinks during iteration. michael@0: michael@0: function ispal(arr) { michael@0: for (var v of arr) { michael@0: if (v !== arr.pop()) michael@0: return false; michael@0: } michael@0: return true; michael@0: } michael@0: michael@0: assertEq(ispal([1, 2, 3, 4, 3, 2, 1]), true); michael@0: assertEq(ispal([1, 2, 3, 3, 2, 1]), true); michael@0: assertEq(ispal([1, 2, 3, 4, 2, 1]), false);