true
if the string is a palindrome or false
if it is not.palindrome('abba') //--> true
palindrome('abcdefg') //--> false
My Solution
function palindrome(str) {
const lastIndex = str.length - 1
const midPoint = Math.floor(lastIndex / 2);
for (let i = 0; i <= midPoint; i++) {
if (str[i] === str[lastIndex - i]) {
continue
} else {
return false
}
}
return true
}
SG Solution 1
function palindrome(str) {
const reversed = str.split('').reverse().join('');
return reversed === str;
}
SG Solution 2
function palindrome(str) {
const strLen = str.length - 1;
return str.split('').every((char, i) => char === str[strLen - i]);
}