Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

how to check the number is palindrome or not

function isPalindrome(num) {
   const temp = num.toString().split('').reverse().join('') * 1;
   return (result = num === parseInt(temp) ? true : false);
}

console.log(isPalindrome(121));
console.log(isPalindrome(320));
Comment

is palindrome

const isPalindrome = (str) => {
    
    const preprocessing_regex = /[^a-zA-Z0-9]/g,
    processed_string = str.toLowerCase().replace(preprocessing_regex , ""),
    integrity_check = processed_string.split("").reverse().join("");
    if(processed_string === integrity_check) return true
    else return false
         
        }

//if you find this answer is useful ,
//upvote ⇑⇑ , so can the others benefit also . @mohammad alshraideh ( ͡~ ͜ʖ ͡°)
Comment

Palindrome Checker

/*
	C++ Palindrome Checker program by lolman_ks.
    Checks palindromic string WITHOUT reversing it.
    Same logic can be used to build this program in other languages.
*/
  
 /*
	 Logic: In a palindromic string, the 1st and last, 2nd and 2nd last, and so
     on characters are equal.
     Return false from the function if any of these matches, i.e (1st and last),
     (2nd and 2nd last) are not equal.
 */

#include <iostream>
using namespace std;

bool checkPalindromicString(string text){
  int counter_1 = 0; //Place one counter at the start.
  int counter_2 = text.length() - 1; //And the other at the end.

  //Run a loop till counter_2 is not less that counter_1.
  
  while(counter_2 >= counter_1){
    if(text[counter_1] != text[counter_2]) return false; //Check for match.
    //Note: Execution of a function is halted as soon as a value is returned.
    
    else{
      ++counter_1; //Move the first counter one place ahead.
      --counter_2; //Move the second character one place back.
    }
  }
  return true; 
  /*
  	Return true if the loop is not broken because of unequal characters and it
    runs till the end.
    If the loop runs till the condition specified in it, i.e 
    (counter_2 >= counter1), that means all matches are equal and the string is 
    palindromic.
  */
}

//Implementation of the function.

int main(){
  cout << checkPalindromicString("racecar") << endl; //Outputs 1 (true).
  cout << checkPalindromicString("text") << endl; //Outputs 0 (False).
  
  if(checkPalindromicString("lol")){
  	cout << "#lolman_ks";
  }
  //Outputs #lolman_ks.
  
  return 0;
}

//I hope this would be useful to you all, please promote this answer if it is.
//#lolman_ks
Comment

check for palindromes

function palindrome(str) {
  var re = /[W_]/g;// representing Non-alphanumetic characters
  var lowRegStr = str.toLowerCase().replace(re, '');
  var reverseStr = lowRegStr.split('').reverse().join(''); 
  return reverseStr === lowRegStr;
}
palindrome("A man, a plan, a canal. Panama");
Comment

Palindrome Checker

const palindrome = str = {
  str = str.replace(/[W+|_]/g, '').toLowerCase()
  
  const str1 = str.split('').reverse().join('')

  return str1 === str
}

palindrome("My age is 0, 0 si ega ym.");

// With love @kouqhar
Comment

Palindrome Number

class Solution {
public:
    bool isPalindrome(int x) {
        
    }
};
Comment

palindrome number

let data = 12421

const dataOne = data.toString().split("").reverse().join("");
data = data.toString();

dataOne === data ? console.log("Palindrom")
  : console.log("Not Palindorm"); 
Comment

Palindrome Checker

// The Setup
function palindrome(str) {

  // Using Regex to remove all the special character, converted all the string to lowercase to ease working with and assign it to a new variable 
  let newStr = str.replace(/[^a-zA-Z0-9]/g, '').toLowerCase();

  // Split the string, reverse, join then assign it to a new variable
  let revStr = newStr.split('').reverse().join('');

  // return their value
  return newStr === revStr;

}

palindrome("A man, a plan, a canal. Panama");
Comment

Palindrome Number

var isPalindrome = function(x) {
    
let y = x
let r = y.toString().split('').reverse().join('')

let t = Number(r)

if(t ===x){
  return true
}
else{ 
  return false}


}
Comment

check if palindrome

function isPalindrome(str) {
  str = str.toLowerCase();
  return str === str.split("").reverse().join("");
}
Comment

palindrome number


 while(n>0){    
   r=n%10;  //getting remainder  
   sum=(sum*10)+r;    
   n=n/10;    
  }    
Comment

fastest way to check a number is palindrome

function palindromeNumber(num) {
  	let numStr = num.toString();
    return numStr === numStr.toString().split("").reverse().join("");
}
Comment

what is palindrome

function Palindrome(str) { 

  str = str.replace(/ /g,"").toLowerCase();
  var compareStr = str.split("").reverse().join("");

  if (compareStr === str) {
    return true;
  } 
  else {
    return false;
  } 

}
Comment

Valid Palindrome

class Solution :
   def isPalindrome(self, string: str ) :
       '''
       A function to check if a string is Palindrome or not!
       :param string: string to be checked
       :return: True if it is palindrome else False
       '''
       string = string.lower()
       s_stripped = ''.join(list( filter ( lambda x : x.isalnum () == True , string)))
       return s_stripped == s_stripped[::-1]


if __name__ == '__main__' :
   string = 'Was it a car or a cat I saw!!'
   print (f'Is "{string}" a palindrome? : {Solution ().isPalindrome (string)}')
   string2 = 'A man, a plan,'
   print (f'Is "{string2}" a palindrome? : {Solution ().isPalindrome (string2)}')
Comment

Palindrome Number

class Solution {
    public boolean isPalindrome(int x) {
        
    }
}
Comment

Palindrome Number

public class Solution {
    public bool IsPalindrome(int x) {
        
    }
}
Comment

Palindrome Number

/**
 * @param {number} x
 * @return {boolean}
 */
var isPalindrome = function(x) {
    
};
Comment

Palindrome Number

# @param {Integer} x
# @return {Boolean}
def is_palindrome(x)
    
end
Comment

Palindrome Number

class Solution {
    func isPalindrome(_ x: Int) -> Bool {
        
    }
}
Comment

Palindrome Number

class Solution {

    /**
     * @param Integer $x
     * @return Boolean
     */
    function isPalindrome($x) {
        
    }
}
Comment

valid palindrome

anything
Comment

can be palindrome

// can we generate palindrome string by suffling 
// the character of the string s 
public bool CanBePalindrome(string s)
{
    var dict = new Dictionary<char, int>();
    for (int j =0; j < s.Length; j++)
    {
        var item = s[j];
        if (dict.ContainsKey(item))
        {
            dict[item]++;
            if (dict[item] == 2)
            {
                dict.Remove(item);
            }
        }
        else
        {
            dict.Add(item, 1);
        }
    }
    return dict.Count <= 1;
}
Comment

Palindrome Number

function isPalindrome(x: number): boolean {

};
Comment

Palindrome Number



bool isPalindrome(int x){

}
Comment

PREVIOUS NEXT
Code Example
Javascript :: get contents between tags javascript 
Javascript :: javascript find first element of array 
Javascript :: destructuring 
Javascript :: how to define width with [styles] in percentage in angular 
Javascript :: jest called times 
Javascript :: require("readline") noe js 
Javascript :: d3.js click event 
Javascript :: open dev server 
Javascript :: what is javascript used for 
Javascript :: how to check if username already exists in database using javascript 
Javascript :: localstorage syntax 
Javascript :: using connect flash 
Javascript :: jquery on method 
Javascript :: fullscreen api 
Javascript :: preventing form from submitting 
Javascript :: Get the Middle Character 
Javascript :: deno vs node 
Javascript :: js regex find text inside single quotes 
Javascript :: recursive function javascript 
Javascript :: hide and open jquery 
Javascript :: how to get keys in an object javascript 
Javascript :: array.fill() in javascript 
Javascript :: javascript dom manipulation 
Javascript :: side effect, useEffect, return 
Javascript :: javascript detect if the browser tab is active 
Javascript :: best way to setup nextjs project 
Javascript :: how to print 1 to 10 table in javascript 
Javascript :: react spread operator 
Javascript :: axios delete set content type 
Javascript :: caching in javascript 
ADD CONTENT
Topic
Content
Source link
Name
9+5 =