palindrome in javascript
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; }
palindrome in javascript
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; }
Function Palindrome JavaScript
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'
javascript palindrome check
const isPalindrome = str => str === str.split('').reverse().join(''); // Examples isPalindrome('abc'); // false isPalindrom('abcba'); // true
js palindrome number
isPalindrome = function(x) { if (x < 0) { return false; } return x === reversedInteger(x, 0); }; reversedInteger = function(x, reversed) { if(x<=0) return reversed; reversed = (reversed * 10) + (x % 10); x = Math.floor(x / 10); return reversedInteger(x, reversed); };
javascript palindrome
function remove_spaces_strict(string) { return string.replace(/\s/gm, ""); } function to_lower_case(string="") { return string.toLocaleLowerCase(); } function isPalindrome(string) { let string1 = string; if (typeof string === 'string' || typeof string === 'number') { if (typeof string === 'number') { string1 = new Number(string1).toString(); } string1 = remove_spaces_strict(string1); string1 = to_lower_case(string1); let len1 = string1.length; let len = Math.floor(string1.length / 2); let i = 0; while(i < len) { if (string1[i] !== string1[len1 - (1 + i)]) { return false; } console.log(string1[i] + " = " + string1[len1 - (1 + i)]); i++; } }else{ throw TypeError(`Was expecting an argument of type string1 or number, recieved an argument of type ${ typeof string1}`); } return string; }
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us