code.ashish.me

Atom feed

Recently added: 02 Count Of Subset Sum, 416 Partition Equal Subset Sum, 01 Subset Sum, 518 Coin Change 2, 983 Minimum Cost For Tickets

03 Palindrome

/**
 * Created by Ashish Patel
 * Copyright © 2017 ashish.me
 * ashishsushilpatel@gmail.com 
 */

/**
 * Problem:
 * Return true if the given string is a palindrome. Otherwise, return false.
 * A palindrome is a word or sentence that's spelled the same way both forward and backward, ignoring punctuation, case, and spacing.
 * Note You'll need to remove all non-alphanumeric characters (punctuation, spaces and symbols) and turn everything lower case in order to check for palindromes.
 */

 function checkForPalindrome(str){
    const originalStr = str.replace(/\W|_/g, "").toLowerCase();
    const reverseStr = originalStr.split('').reverse().join('');
    return originalStr === reverseStr;
 }
 
 console.log(checkForPalindrome("eyE"));

Created 2019-11-24T04:41:20+05:18 · Edit