function palindrome(str) {
var len = str.length;
var mid = Math.floor(len/2);
for ( var i = 0; i < mid; i++ ) {
if (str[i] !== str[len - 1 - i]) {
return false;
}
}
return true;
}
// Palindrom or not
// l e v el
const palindrome = (data) => {
var len = data.length;
var mid = Math.floor(len / 2);
for (var i = 0; i < mid; i++) {
if (data[i] !== data[len - 1 - i]) {
return false;
}
}
return true;
}
console.log(palindrome("level"))
function solution(inputString) {
const charCount = {};
for (let i = 0; i < inputString.length; i++) {
if (charCount[inputString[i]]) {
charCount[inputString[i]]++;
} else {
charCount[inputString[i]] = 1;
}
}
let oddCount = 0;
for (let key in charCount) {
if (charCount[key] % 2 === 1) {
oddCount++;
}
}
return oddCount <= 1;
}
function isPalindrome(str) {
str = str.replace(/W/g, '').toLowerCase();
return (str == str.split('').reverse().join(''));
}
console.log(isPalindrome("level")); // logs 'true'
console.log(isPalindrome("levels")); // logs 'false'
console.log(isPalindrome("A car, a man, a maraca")); // logs 'true'
function isPalindrome(s) {
var len = s.length;
if (len < 2) {
return true;
}
var i = 0;
var j = len - 1;
while (i < j) {
if (s[i] != s[j]) {
return false;
}
i += 1;
j -= 1;
}
return true;
}
function palindrome(str) {
var splitted = str.split("");
var reversed = splitted.reverse("");
var joined = reversed.join("");
return joined.toLowerCase().replace(/[^0-9a-z]/gi, '') == str.toLowerCase().replace(/[^0-9a-z]/gi, '')
}
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 ( ͡~ ͜ʖ ͡°)