I'm trying to write a function that takes another function and then executes it in reverse. And it don't work :( Mistake is: TypeError: isPalindrome is not a function. Where is a problem?
const isPalindrome = (text) => {
let text1 = text.toLowerCase();
let text2 = text1.split('').reverse().join('');
return text1 === text2;
}
const isNotPalindrome = (isPalindrome) => {
!isPalindrome();
};
If you really want to encapsulate it into a method you can do that:
const isPalindrome = (text) => {
let text1 = text.toLowerCase();
let text2 = text1.split('').reverse().join('');
return text1 === text2;
}
const isNotPalindrome = (text) => !isPalindrome(text);
console.log(isPalindrome('test'));
console.log(isNotPalindrome('test'));
However, since it does not make really sense to create a method to just return the opposite you could simply do:
const isPalindrome = (text) => {
let text1 = text.toLowerCase();
let text2 = text1.split('').reverse().join('');
return text1 === text2;
}
console.log(isPalindrome('test'));
console.log(!isPalindrome('test'));