Skip to content

Instantly share code, notes, and snippets.

@iburlakov
Created February 10, 2020 19:33
Show Gist options
  • Save iburlakov/f7e9445ff13960e95d4d4ac82e39d697 to your computer and use it in GitHub Desktop.
Save iburlakov/f7e9445ff13960e95d4d4ac82e39d697 to your computer and use it in GitHub Desktop.
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