Created
February 10, 2020 19:33
-
-
Save iburlakov/f7e9445ff13960e95d4d4ac82e39d697 to your computer and use it in GitHub Desktop.
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 characters
function isPalindrome(str) { | |
if (!str) return false; | |
let i = 0; | |
do { | |
if (str[i] != str[str.length - 1 - i]) { | |
return false; | |
} | |
i++; | |
}while(i < str.length - i); | |
return true; | |
} | |
function test(str) { | |
console.log(`'${str}' -> ${isPalindrome(str)}`); | |
} | |
test(undefined); | |
test(null); | |
test(""); | |
test(" "); | |
test("abba"); | |
test("aba"); | |
test("ab"); | |
test("abc"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment