Created
September 8, 2015 21:00
-
-
Save jluismm2311/e6023ebcf5a6c252319f to your computer and use it in GitHub Desktop.
A palindrome is a word, phrase, number, or other sequence of symbols or elements, whose meaning may be interpreted the same way in either forward or reverse direction. Famous examples include "Amore, Roma", "A man, a plan, a canal: Panama" and "No 'x' in 'Nixon'". - wikipedia Our goal is to determine whether or not a given string is a valid pali…
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
function palindrome(string) { | |
let newString = string.replace(/\W/g, '').toLowerCase(); | |
let stringLength = newString.length, midleString = stringLength % 2 === 0 ? stringLength / 2 : ((stringLength / 2)+1); | |
for(i = 0; i< midleString; i++){ | |
if(newString[i] != newString[stringLength - 1 - i]){ | |
return false; | |
} | |
} | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment