Add palindrome checker certification project
This commit is contained in:
parent
ffd2b35c17
commit
42076040bc
1 changed files with 18 additions and 0 deletions
|
@ -0,0 +1,18 @@
|
|||
function reverseString(str){
|
||||
return str.split("").reverse().join("")
|
||||
}
|
||||
|
||||
function cleanUpString(str){
|
||||
return str.replaceAll(/[^a-zA-Z0-9]/g, "").toLowerCase()
|
||||
}
|
||||
function palindrome(str) {
|
||||
str = cleanUpString(str);
|
||||
let checkstring = reverseString(str);
|
||||
return checkstring === (str);
|
||||
}
|
||||
|
||||
let test1 = palindrome("eye"); //true
|
||||
let test2 = palindrome("A man, a plan, a canal. Panama");//true
|
||||
let test3 = palindrome("not a palindrome");//false
|
||||
let test4 = palindrome("0_0 (: /-\ :) 0-0")//true
|
||||
console.log(test1, test2, test3, test4)
|
Reference in a new issue