228k views
5 votes
Write a simple function (less than 160 characters) that returns a boolean indicating whether or not a string is a palindrome.

User JimLohse
by
7.9k points

1 Answer

4 votes

Final answer:

A palindrome is a word or phrase that reads the same forwards and backwards. To check if a string is a palindrome, you can create a function that compares the string with its reverse. If they are the same, then the string is a palindrome.

Step-by-step explanation:

To check if a string is a palindrome, you can create a function that compares the string with its reverse. If they are the same, then the string is a palindrome. Here is an example:

<pre>

function

isPalindrome(str) {

return

str === str.split('').reverse().join('');

}

console.log(isPalindrome('level')); // returns true

console.log(isPalindrome('hello')); // returns false

</pre>

User Gjvatsalya
by
8.0k points