Skip to content

Instantly share code, notes, and snippets.

@danielcodes
Created December 8, 2020 19:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielcodes/a42ee69ecc266cab6b41ad8570cd96cb to your computer and use it in GitHub Desktop.
Save danielcodes/a42ee69ecc266cab6b41ad8570cd96cb to your computer and use it in GitHub Desktop.
// problem 1
function palindromeCheck(s) {
// remove non alphanumeric chars
let formatted = s.replace(/[^a-z0-9]/gi,'').toLowerCase();
let start = 0;
let end = formatted.length-1;
while (start < end) {
if (formatted[start] != formatted[end]) {
return false;
}
start += 1;
end -= 1;
}
return true;
}
const strings = ["oscar", "aaaa", "Racecar", "Madam, I'm Adam"];
for(let i=0; i<strings.length; i++){
console.log(palindromeCheck(strings[i]));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment