Skip to content

Instantly share code, notes, and snippets.

@lienista
Last active August 28, 2018 07:41
Show Gist options
  • Select an option

  • Save lienista/481b68eec763d8785802816450ae3a13 to your computer and use it in GitHub Desktop.

Select an option

Save lienista/481b68eec763d8785802816450ae3a13 to your computer and use it in GitHub Desktop.
Algorithms in Javascript: CTCI 1.4 Palindrome Permutation: Given a string, determine if it is a permutation of a palindrome.
const isPermutation = (s1, s2) => {
if(s1.length != s2.length) return false;
return s1.split('').sort().join('') === s2.split('').sort().join('');
}
let a = isPermutation("paypalishiring", "palpayhiringis"); // true
let b = isPermutation("paypalishiring", "hiringpalsipay"); // true
let c = isPermutation("paypalishiring", "palpayhirising"); // true
let d = isPermutation("paypalishiring", "palpayhiringgg"); // false
console.log(a + ', ' + b + ', ' + c + ', ' + d);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment