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

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 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

is_palindrome

#include <stdio.h>
#include <stdbool.h>

bool is_palindrome(int n ){
    int rev = 0, orig = n;
    while( n != 0){
        rev = 10*rev + (n % 10);
        n = n/10;
    }
    return orig == rev;

}
int main() {
    printf("Enter a number");
    int n = 0;
    if( scanf("%d",&n)!=1 ){
        prinf("Bad input
");
    }else{
        if(is_palindrome(n))
            printf("%d is a palindrome", n);
        else
            prinf("%d is not a palindrome", n);
    }
    return 0;
}
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

check if string is a palindrome

<script>
  // function that check str is palindrome or not
  function check_palindrome( str )
  {
    let j = str.length -1;
    for( let i = 0 ; i < j/2 ;i++)
    {
      let x = str[i] ;//forward character
      let y = str[j-i];//backward character
      if( x != y)
      {
        // return false if string not match
        return false;
      }
    }
    /// return true if string is palindrome
    return true;
     
  }
 
  //function that print output is string is palindrome
  function is_palindrome( str )
  {
    // variable that is true if string is palindrome
    let ans = check_palindrome(str);
    //condition checking ans is true or not
    if( ans == true )
    {
      console.log("passed string is palindrome ");
    }
    else
    {
      console.log("passed string not a palindrome");
    }
  }
  // test variable
  let test = "racecar";
  is_palindrome(test);
</script>
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

Checking String Palindrome

int main()
{
    char str1[20], str2[20];
    int i, j, len = 0, flag = 0;
    cout << "Enter the string : ";
    gets(str1);
    len = strlen(str1) - 1;
    for (i = len, j = 0; i >= 0 ; i--, j++)
        str2[j] = str1[i];
    if (strcmp(str1, str2))
        flag = 1;
    if (flag == 1)
        cout << str1 << " is not a palindrome";
    else
        cout << str1 << " is a palindrome";
    return 0;
}
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

Checking String Palindrome

int main()
{
    char str1[20], str2[20];
    int i, j, len = 0, flag = 0;
    cout << "Enter the string : ";
    gets(str1);
    len = strlen(str1) - 1;
    for (i = len, j = 0; i >= 0 ; i--, j++)
        str2[j] = str1[i];
    if (strcmp(str1, str2))
        flag = 1;
    if (flag == 1)
        cout << str1 << " is not a palindrome";
    else
        cout << str1 << " is a palindrome";
    return 0;
}
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

is it possible to 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 :: ejs express layouts 
Javascript :: react native lottie 
Javascript :: redux reducer 
Javascript :: javascript get params from query string json object 
Javascript :: DevDependencies and dependencies syntax in Node package.json 
Javascript :: react-native restart app 
Javascript :: how to push two values in array at once 
Javascript :: vue 3 apollo client 
Javascript :: parsley validation checkbox 
Javascript :: javascript Example 1: Regular Expressions 
Javascript :: vs code shortcut for switching to terminal to editor 
Javascript :: aimbot scripts island royale 
Javascript :: how to use labels in javascript 
Javascript :: js array pop 
Javascript :: gltfjsx 
Javascript :: script tags in react 
Javascript :: mangoosejs 
Javascript :: javascript array multidimensional push 
Javascript :: how to pass headers in axios 
Javascript :: how to practice javascript 
Javascript :: how to set css in hbs in express 
Javascript :: libuv nodejs 
Javascript :: .pop js 
Javascript :: escape sequence in js 
Javascript :: splice method in javascript 
Javascript :: vue font awesome icons 
Javascript :: css react 
Javascript :: vscode add shortcut to run in terminal 
Javascript :: responseText js 
Javascript :: video conferencing app with html and js 
ADD CONTENT
Topic
Content
Source link
Name
4+5 =