Problem: Checking if a word is a palindrome.
Problem Definition: A palindrome is a word which when spelled from left to right is the same if it is spelt from right to left. This kind of word is referred to as Palindrome.
Algorithm
I converted the given string to lowercase and replace all non word characters with a white space.
I then splitted the converted string, arrange it from last to first and then joined the characters together.
I compared the string in step 2 and 1 above then, returned true if both strings are the same.
JavaScript Code
function palindrome(str){
let palindrome = str.toLowerCase().replace(/[^a-z0-9]/, " ");
if(palindrome === palindrome.split(" ").reverse(" ").join(" ") ) {
return true;}
else{return false}
};
palindrome("eye");