rurtubia
12/19/2015 - 11:47 AM

My solution to FreeCodeCamp bonfire number 4

My solution to FreeCodeCamp bonfire number 4

function palindrome(str) {
  
  //converts everything to lower case
  str = str.toLowerCase();
  
  //eliminates spaces from string
  str = str.replace(/ /g,'');
  
  //removes: '/', '_', '\', '(', ')', '.', ',', '-' from the string
  //'-' must be declared at the end of the string
  str = str.replace(/[/_\\{()}.,-]/g, '');
  
  //stores the string for future comparisons as a new variable
  var str2 = str;
  
  //splits the string into an array
  var tempArray = str.split('');
  
  //reverses the elements of the array
  tempArray = tempArray.reverse();
  
  //joins the array elements into a string
  str = tempArray.join('');
  
  
  //Compares the stored string with the new one
  if(str2 === str)
    return true;
  else
    return false;

}



palindrome("something");