Created
March 27, 2024 10:29
Revisions
-
juque created this gist
Mar 27, 2024 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,26 @@ function isPalindrome(str) { str = str.replace(/[^a-z0-9]/i, '').toLowerCase(); if ( str.length === 0) { return true; } let left = 0; let right = str.length - 1; while ( left < right ) { if ( str[left] !== str[right] ) { return false; } left++; right--; } return true; } console.log(isPalindrome('kayak')); console.log(isPalindrome('radar')); console.log(isPalindrome('letters'));