3
06/11/2024 10:44 am
Topic starter
Write a JS function (program) that checks if an input string is a palindrome. See what is a palindrome: https://en.wikipedia.org/wiki/Palindrome
The input comes as a single string argument.
Examples:
Input: haha
Output: false
Input: racecar
Output: true
Input: unitinu
Output: true
The output is the return value of your function. It should be true if the string is a palindrome and false if it’s not.
1 Answer
2
06/11/2024 10:45 am
Here is my palindrome:
/** * * @param str {string} * @returns {boolean} */ function isPalindrome(str) { for (let i = 0; i < str.length / 2; i++) { if (str[i] != str[str.length - i - 1]) { return false; } } return true; } console.log(isPalindrome("abba"));