Skip to content

Instantly share code, notes, and snippets.

@jluismm2311
Created September 8, 2015 21:00
Show Gist options
  • Save jluismm2311/e6023ebcf5a6c252319f to your computer and use it in GitHub Desktop.
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…
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