MY #100 DAYS OF CODE CHALLENGE JOURNEY-DAY 4

in #coding6 years ago

IMG_20190125_193037.jpg

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

  1. I converted the given string to lowercase and replace all non word characters with a white space.

  2. I then splitted the converted string, arrange it from last to first and then joined the characters together.

  3. 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");

Coin Marketplace

STEEM 0.21
TRX 0.20
JST 0.034
BTC 98477.90
ETH 3327.94
USDT 1.00
SBD 3.07