isPalindrome #4

by Abhishek Kumar

JavaScript

function isPalindrome1(word) {
  var word = word.toLowerCase();
  var a, b;
  if (word.length % 2 == 0) {
    a = word.substring(0, word.length / 2);
    b = word.substring(word.length / 2, word.length);
  } else {
    a = word.substring(0, Math.floor(word.length / 2));
    b = word.substring(Math.ceil(word.length / 2), word.length);
  }
  var c = b.split('').reverse().join('');
  console.log(word, word.length % 2, a, b, c);
  return a === c;
}

function isPalindrome(word) {
  var word = word.toLowerCase();
  var len = word.length;
  for (var i = 0; i < len / 2; i++) {
		if (word[i] != word[len - 1 - i])
    	return false;
  }
  return true;
}
console.log(isPalindrome('Deleveled'))
console.log(isPalindrome('adam'))
console.log(isPalindrome('abccba'))
console.log(isPalindrome('zyxwxyz'))