DEV Community

Discussion on: Javascript Algorithms #2: Palindromes

Collapse
 
kepta profile image
Kushan Joshi • Edited

Great explanation Justine, especially using the .each API. Since javascript is so versatile, I am adding one more solution which uses iterator from my previous article dev.to/kepta/how-i-learned-to-stop...

function isPalindrome(str) {
   const iter = [...str.toLowerCase()];
   for (let char of iter) {
      if (char !== iter.pop()) { return false}
   }
   return true
}

The good thing about this is that it iterates only over half of the string to check if it is palindrome.

Collapse
 
luc_tuyishime profile image
jean luc tuyishime

Do you have an idea on how you can do permutation of palindrome??