Palindrom

Palindrom

A palindrome is a word, number, phrase, or other sequence of characters which reads the same backward as forward, such as ‘’taco cat’’ or madam or racecar or the number 10801

Given a string, return true if the string is a palindrome or false if it is not.

##For Example console.log(reverse(‘hannah’)) true
console.log(reverse(‘apple’)) false

function palindrome(str) {
	const reversed = str.split('').reversed().join('');
	return str === reversed
}
console.log(reverse('hannah')) true <br>
console.log(reverse('apple'))  false <br>
  1. Split the string with split(‘’) that gives me an array that I will reverse().
  2. Then i will chain the reverse() method to split(‘’).reversed() which in turn will reverse the letters.
  3. After that i will chain .join(‘’) which is used to join the elements of an array into a string.
  4. Finally if parameter str is strong equal to reversed we return it.It will be eather true or false depending on the tests.
comments powered by Disqus