Skip to content

Instantly share code, notes, and snippets.

@AntonisFK
Created April 14, 2016 19:35
Show Gist options
  • Save AntonisFK/c417437e54879339a9397d88a8a3f096 to your computer and use it in GitHub Desktop.
Save AntonisFK/c417437e54879339a9397d88a8a3f096 to your computer and use it in GitHub Desktop.
returns true if the string is a palindrome. Ignores empty spaces. Javascript
function isPalindrome(str){
var i=0,
j= str.length-1
while(i <j){
if(str[i] == " "){
i++;
}else if(str[j] ==" "){
j--;
}else {
if(str[i].toLowerCase() === str[j].toLowerCase()){
i++
j--
continue;
}else{
return false;
}
}
}
return true;
}
var str = "B x o x B"
isPalindrome(str)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment