o9s
is a microblog
home archives search feed blogroll


Palindrome

A palindrome is a word or a phrase that is the same forward and backward.

function isPalindrome(word) {
  for (let i = 0; i < word.length / 2; i++) {
    if (word[i] != word[word.length - i - 1]) {
      return false;
    }
  }

  return true;
}

if (isPalindrome('bob')) {
  console.log('bob is a palindrome.');
}
Posted on 2018-02-23   #javascript  






← Next post    ยท    Previous post →