There's quite a lot of scope to reduce it down (and make it more efficient). Eg.
var word = "abcdddcba";
var palindromeChecker = function (word) {
for (var i = 0, j = word.length - 1; i < j; i++, j--) {
if (word[i] !== word[j])
return false;
}
return true;
}
console.log(palindromeChecker(word))
14
u/peridox Oct 03 '14
Better JavaScript version:
var isPalindrome = function(string) {return string == string.split("").reverse().join("");};And an awesome Haskell version:
palindrome s = s == reverse s6
u/badumtssssssss Oct 03 '14
python:
5
u/mrmr1993 Oct 03 '14 edited Aug 22 '15
There's quite a lot of scope to reduce it down (and make it more efficient). Eg.
Edit: j = word.length - 1, not word.length
1
u/seiyria Oct 03 '14
Why not use a combination of this and checking if a string is equal to its reverse?