Nodejs String Palindrome Check isPalindrome()

Here you can find the source of isPalindrome()

Method Source Code

var isPalindrome = function(str){
  var i = 0;//ww w . j  av  a  2s.  c om
  var j = str.length-1;
  while (i <= j){
    if (str[i] != str[j]){
      return false;
    }
    i++;
    j--;
  }
  return true;
}

var isPalindrome2 = function(string){
  for (var i = 0, j = string.length-1; i < string.length/2; i++, j--){
    if (string[i] != string[j]){
      return false;
    }
  }
  return true;
}

String.prototype.isPalindrome = function(){
  // return isPalindrome(this);
  var i = 0;
  var j = this.length-1;
  while (i <= j){
    if (this[i] != this[j]){
      return false;
    }
    i++;
    j--;
  }
  return true;
}

Related

  1. isPalindrome()
    String.prototype.isPalindrome=function(){
      var palavra=this;
      for(var i=0;i<palavra.length/2;i++){
        if(palavra[i]!=palavra[palavra.length-1-i]){
          return false;
      return true;
    
  2. isPalindrome()
    String.prototype.isPalindrome = function() {
      var val = this.toString().toLowerCase();
      var reverse = val.split('').reverse().join('');
      return val === reverse;
    var str = 'something';
    var result = str.isPalindrome();  
    var str2 = 'level';
    var result2 = str2.isPalindrome();  
    ...
    
  3. isPalindrome()
    'use strict';
    String.prototype.isPalindrome = String.prototype.isPalindrome || function () {
      let length = Math.floor(this.length / 2);
      for (let i = 0; i < length; i++) {
        if (this[i] !== this[this.length - i - 1]) {
          return false;
      return true;
    ...
    
  4. isPalindrome()
    String.prototype.isPalindrome = function () {
      return this.valueOf() === this.reverse().valueOf();
    };
    String.prototype.reverse = function () {
      return Array.prototype.slice.apply(this).reverse().join('');
    };
    let result = 0;
    for (let i = 999; i > 0; i--) {
      for (let j = i; j > 0; j--) {
    ...
    
  5. isPalindrome()
    var first = 999,
        second = 999,
        largestPalindromicProduct = 0;
    String.prototype.isPalindrome = function() {
      return this == this.reverse();
    while(first > 99) {
      second = first;
      while(second > 99) {
    ...
    
  6. isPalindrome()
    String.prototype.isPalindrome = ()=>{
      return this.replace(/[^a-zA-Z ]/g, "").replace(/ /g,'').trim().toLowerCase() == this.replace(/[^a-zA-Z ]/g, "").replace(/ /g,'').trim().toLowerCase().split('').reverse().join('');
    
  7. isPalindrome()
    var isPalindrome = function(inString) {
      var inString = inString.toLowerCase();
      for (var i = 0, j = inString.length-1; i < inString.length/2; i++, j--) {
        if (inString[i] != inString[j]){
          return false;
      return true;
    String.prototype.isPalindrome = function isPalindrome() {
      console.log(this);
      var new_str = this.toString().replace(" ", "");
      if (new_str == new_str.split("").reverse().join("")) {
        return true;
      } else {
        return false;