code.ashish.me

Atom feed

Recently added: 128 Longest Consecutive Sequence, 347 Top K Frequent Elements, 045 Jump Game 2, 228 Summary Ranges, 219 Contains Duplicate 2

023 Case Insensitive 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 caseInsensitivePalindrome(value) {
  return value.toLowerCase() === value.toLowerCase().split('').reverse().join('')
}

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

Created 2019-12-09T03:27:46+05:30 · Edit