Created
December 8, 2020 19:34
-
-
Save danielcodes/a42ee69ecc266cab6b41ad8570cd96cb to your computer and use it in GitHub Desktop.
This file contains 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
// 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