Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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;
}
Comment

palindrome javascript

// 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"))
Comment

palindrome rearranging javascript

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;
}
Comment

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'

Comment

palindrome number in javascript

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;
}
Comment

palindrome javascript

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, '')
}
Comment

palindrome javascript

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

palindrome javascript

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

PREVIOUS NEXT
Code Example
Javascript :: JavaScript HTML DOM Changing HTML Style 
Javascript :: jquery validation plugin google recaptcha 
Javascript :: javascript find the min in array of numbers 
Javascript :: node read file sync 
Javascript :: jquery loop through collection backwards 
Javascript :: Uncaught TypeError: $(...).DataTable is not a function 
Javascript :: what is ngmodel property binding 
Javascript :: how to get id of current element clicked 
Javascript :: add class jquery 
Javascript :: lodash angular 9 
Javascript :: slickcdn 
Javascript :: jquery window offset top 
Javascript :: random rgba color javascript except black 
Javascript :: sls invoke local 
Javascript :: getting state in react-router-dom v6 
Javascript :: javascript split by backslash 
Javascript :: jquery today date 
Javascript :: js form check all required input 
Javascript :: javascript Capitalise a String 
Javascript :: javascript tolocaletimestring 
Javascript :: catch error message js 
Javascript :: delete a property of html by js 
Javascript :: if datatable is null js 
Javascript :: moment js from now 
Javascript :: command to create custom pipe in angular 6 
Javascript :: nodejs catch uncaught exception 
Javascript :: js check string for isogram 
Javascript :: nesting in react js 
Javascript :: react font awesome 
Javascript :: how to read 2 dimensional array in javascript 
ADD CONTENT
Topic
Content
Source link
Name
4+5 =