isPalindrome

Run Settings
LanguageJavaScript
Language Version
Run Command
'use strict'; const firstCharacter = (str) => str.slice(0, 1); const lastCharacter = (str) => str.slice(-1); const middleCharacters = (str) => str.slice(1, -1); const isPalindrome = (str) => { if (str.length === 0 || str.length === 1) { return true; } if (firstCharacter(str) !== lastCharacter(str)) { return false; } return isPalindrome(middleCharacters(str)); }; console.log('is motor a palindrome?', isPalindrome('motor')); console.log('is rotor a palindrome?', isPalindrome('rotor')); console.log('is B a palindrome?', isPalindrome('B')); console.log('is Lemmy a palindrome?', isPalindrome('Lemmy'));
Editor Settings
Theme
Key bindings
Full width
Lines