Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

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 function

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

function isPalindrome(sometext) {
  var replace = /[.,'!?- "]/g; //regex for what chars to ignore when determining if palindrome
  var text = sometext.replace(replace, '').toUpperCase(); //remove toUpperCase() for case-sensitive
  for (var i = 0; i < Math.floor(text.length/2) - 1; i++) {
    if(text.charAt(i) == text.charAt(text.length - 1 - i)) {
      continue;
    } else {
      return false;
    }
  }
  return true;
}
//EDIT: found this on https://medium.com/@jeanpan/javascript-splice-slice-split-745b1c1c05d2
//, it is much more elegant:
function isPalindrome(str) {
  return str === str.split('').reverse().join(''); 
}
//you can still add the regex and toUpperCase() if you don't want case sensitive
Comment

palindrome

#palindrome program in python
n=int(input('Enter a number :'))
num=n
rev=0

while n>0:
 r=n%10
 rev=rev*10+r
 n//=10
print('Reverse of',num,'=',rev)
if rev==num:
  print(num,'is a palindrome number')
else :
  print(num,'is not a palindrome number')
#output
Enter a number :132
Reverse of 132 = 231
132 is not a palindrome numbe
________________________________________________________________________________
Enter a number :451
Reverse of 451 = 154
451 is not a palindrome number
________________________________________________________________________________
Enter a number :12321
Reverse of 12321 = 12321
12321 is a palindrome number
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

def is_palindrome(s):
    string = s
    if (string==string[::-1]):
        print("The string IS a palindrome")
    else:
        print("The string is NOT a palindrome")
    return
Comment

palindrome

# Note: A palindrome is a string that reads the same forwards and backwards.
def palindrome_function(original_list, user_string):
    # reversing the list
    reversed_list = original_list[::-1]

    # comparing reversed_list to original_list to
    # determine if the original_list is a palindrome
    if reversed_list == original_list:
        print("'" + user_string.lower() + "' is a palindrome.")
    else:
        print("'" + user_string.lower() + "' is not a palindrome!")
        
        
def main():
    # promting user to input a word or phrase
    user_string = input("Enter string: ")
    
    user_list = list(user_string.lower())

	# putting our palindrome_function() to use
    palindrome_function(user_list, user_string)


if __name__ == "__main__":
    main()
Comment

Palindrome

def pal(word):
    isPal = 1
    first = 0
    last = len(word)-1;
    for x in range(last):
        if(word[first]!=word[last]):
            isPal = 0
        first += 1
        last -=1
    return isPal
        
Comment

palindrome

var letters = [];
var word = "racecar"  //bob

var rword = "";

//put letters of word into stack
for (var i = 0; i < word.length; i++) {
    letters.push(word[i]);
}

//pop off the stack in reverse order
for (var i = 0; i < word.length; i++) {
    rword += letters.pop();
}

if (rword === word) {
    console.log("The word is a palindrome");
}
else {
    console.log("The word is not a palindrome");
}   
Comment

palindrome

function isPalindrome(word) {
	// Step 1- Put a pointer at each extreme of the word
    // Step 2 - Iterate the string "inwards"
	// Step 3 - At each iteration, check if the pointers represent equal values
	// If this condition isn't accomplished, the word isn't a palindrome
    let left = 0
    let right = word.length-1

    while (left < right) {
        if (word[left] !== word[right]) return false
        left++
        right--
    }
    
    return true
}

isPalindrome("neuquen") // true
isPalindrome("Buenos Aires") // false
Comment

palindrome

// Should Check if the argument passed is a string
function isPalindrome(str){
	return typeof str === "string"
		? str.split("").reverse().join("") === str
		: "Value is not a type string";
}
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 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

palindrome

# Program to check if a string is palindrome or not

my_str = 'aIbohPhoBiA'

# make it suitable for caseless comparison
my_str = my_str.casefold()

# reverse the string
rev_str = reversed(my_str)

# check if the string is equal to its reverse
if list(my_str) == list(rev_str):
   print("The string is a palindrome.")
else:
   print("The string is not a palindrome.")
Comment

fastest way to check a number is palindrome

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

palindrome

function palindrome(str) {
	if (str.toLowerCase() === str.toString().toLowerCase().split('').reverse().join('')) {
		return true;
	} else {
		return false;
	}
}
Comment

palindrome

//Reverses every character in the string
func Reverse(s string) (result string){
	for _,v := range s {
	  result = string(v) + result
	}
	return 
    }

//Check if the string is same as it is reversed
func Check(s string) (b bool){
	a := Reverse(s)
	if s == a{
		b = true
	}else {
		b = false
	}
	return
}
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

Input: s = "race a car"
Output: false
Explanation: "raceacar" is not a palindrome.
Comment

palindrome

Input: s = "race a car"
Output: false
Explanation: "raceacar" is not a palindrome.
Comment

valid palindrome

anything
Comment

Palindrome Number

class Solution {

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

Palindrome Number

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

Palindrome Number

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

Palindrome Number

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

Palindrome Number

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

Palindrome Number

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

palindrome short way

function palindrome2(str) {
	return str.toLowerCase() === str.toString().toLowerCase().split('').reverse().join('') ? true : false;
}
Comment

Palindrome

import java.util.Scanner;
class Palindrome {
    public static void main(String args[]) {
        String original, reverse = "";
        Scanner s1 = new Scanner(System.in);
        System.out.println("Enter a word");
        original = "cat";
        int length = original.length();
        for ( int i = length - 1; i >= 0; i-- )
            reverse = reverse + original.charAt(i);
        if (original.equals(reverse))
            System.out.println("true");
        else
            System.out.println("false");
    }
}
Comment

palindrome

function isPalindrome(text) {
  return [...text].reverse().join('') === text;
}

isPalindrome = text => {
	return [...text].reverse().join('') === text;
}

isPalindrome = text => [...text].reverse().join('') === text;
Comment

is palindrom


#include <iostream>
#include <deque>
bool is_palindrome(const std::string &s){

    if(s.size() == 1 ) return true;
    std::deque<char> d ;
    for(char i : s){
        if(std::isalpha(i)){
           d.emplace_back( toupper(i) );
        }
    }

    auto front = d.begin();
    auto back = d.rbegin();
    while( (front != d.end()) || (back != d.rend())){
        bool ans = (*front == *back);
        if(!ans){
            return ans;
        }
        ++front;++back;
    }

    return true;


}

int main() {
    std::string s = "A man, a plan, a cat, a ham, a yak, a yam, a hat, a canal-Panama!";
    std::cout << std::boolalpha << is_palindrome(s) << std::endl;
    return 0;
}
Comment

Palindromes

// 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
Csharp :: c# enum to string 
Csharp :: integer to boolean conversion in unity C# 
Csharp :: c# capitalize first letter of each word in a string 
Csharp :: how to not overwrite a text file in c# 
Csharp :: javas 
Csharp :: c# blazor in .net framework 
Csharp :: unity NetworkBehaviour the type or namespace could not be found 
Csharp :: unity c# flip sprite 
Csharp :: c# literals 
Csharp :: c sharp or operator in if statement 
Csharp :: freelance 
Csharp :: C# IEnumerable access element at index 
Csharp :: Task w = Task.Delay(600);w.Wait();new Program().Start(); 
Csharp :: wie macht man eine schleife in c# 
Csharp :: webbrowser control feature_browser_emulation compatible 
Csharp :: 10x10 table matrix C# 
Html :: html meta redirect 
Html :: boostrap row reverse utility 
Html :: placeholder select html 
Html :: bootstrap Bootstrap link 
Html :: upload only image input tag 
Html :: _blank in html 
Html :: how to link your js file to html 
Html :: viewport meta 
Html :: vuejs double click 
Html :: html favicon 
Html :: link to send email with subject 
Html :: open whatsapp html 
Html :: href phone 
Html :: how to make a link in hml 
ADD CONTENT
Topic
Content
Source link
Name
4+6 =