Skip to content

Instantly share code, notes, and snippets.

@aliaksandr-s
Last active November 23, 2017 18:24
Show Gist options
  • Save aliaksandr-s/e7ba88cb897c91c5b8902cc709f40393 to your computer and use it in GitHub Desktop.
Save aliaksandr-s/e7ba88cb897c91c5b8902cc709f40393 to your computer and use it in GitHub Desktop.
isPalindrome function
let str = "А по морде ведром - опа!";
const isPalindrome = (str) => {
const getLetter = (n, list) => {
return list[n].toLowerCase();
}
const helper = (firstNum, lastNum, list) => {
const testExp = /[^a-zA-Za-яА-Я]/;
if (testExp.test(getLetter(firstNum, list)) ) {
return helper(firstNum + 1, lastNum, list)
} else if (testExp.test(getLetter(lastNum, list))) {
return helper(firstNum, lastNum - 1, list)
}
if (getLetter(firstNum, list) !== getLetter(lastNum, list)) {
return false;
}
if (lastNum === 0) {
return true;
}
return helper(firstNum + 1, lastNum - 1, list)
}
return helper(0, str.length - 1, [...str])
}
console.log(isPalindrome(str))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment