Is String Palindrome - Node.js String

Node.js examples for String:Algorithm

Description

Is String Palindrome

Demo Code

String.prototype.isPalindrome = function() {
  var str = this;
  var half = parseInt(str.length / 2, 10);

  for (var i = 0, last = str.length - 1; i < half; ++i) {
    if (str[i] != str[last - i]) return false;
  }//from   w  w  w .ja v a 2 s  .  c o  m

  return true;
};

Related Tutorials