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

026 Check Palindrome

/**
 * 
 * Ashish Patel
 * e: ashishsushilPatel@gmail.com
 * w: https://ashish.me
 *
 */

 /* 
Given a string, check if it can become a palindrome through a case change of some (possibly, none) letters.

Example

For inputString = "AaBaa", the output should be isCaseInsensitivePalindrome(inputString) = true.
"aabaa" is a palindrome as well as "AABAA", "aaBaa", etc

For inputString = "abac", the output should be isCaseInsensitivePalindrome(inputString) = false.
All the strings which can be obtained via changing case of some group of letters, i.e. "abac", "Abac", "aBAc" and 13 more, are not palindromes.
*/

function checkPalindrome(value) {
  return value.toLowerCase() === value.toLowerCase().split('').reverse().join('')
}

test('case Insensitive Palindrome', () => {
  expect(checkPalindrome('AaBaa')).toEqual(true)
  expect(checkPalindrome('abac')).toEqual(false)
});

Created 2019-12-09T03:15:46+05:18 · Edit