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));
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 ( ͡~ ͜ʖ ͡°)
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");
<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>
function isPalindrome(str) {
str = str.toLowerCase();
return str === str.split("").reverse().join("");
}
function palindromeNumber(num) {
let numStr = num.toString();
return numStr === numStr.toString().split("").reverse().join("");
}
function Palindrome(str) {
str = str.replace(/ /g,"").toLowerCase();
var compareStr = str.split("").reverse().join("");
if (compareStr === str) {
return true;
}
else {
return false;
}
}
function palindrome2(str) {
return str.toLowerCase() === str.toString().toLowerCase().split('').reverse().join('') ? true : false;
}
// 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;
}