Skip to content

Commit 0580df0

Browse files
committed
updated palindrome to be slightly more efficient
1 parent f2df767 commit 0580df0

File tree

1 file changed

+1
-4
lines changed

1 file changed

+1
-4
lines changed

chapter13/palindrome.html

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,10 @@
77

88
String.prototype.palindrome = function() {
99
var len = this.length-1;
10-
for (var i = 0; i <= len; i++) {
10+
for (var i = 0; i <= len/2; i++) {
1111
if (this.charAt(i) !== this.charAt(len-i)) {
1212
return false;
1313
}
14-
if (i === (len-i)) {
15-
return true;
16-
}
1714
}
1815
return true;
1916
};

0 commit comments

Comments
 (0)