Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

333
Visualizações
Function in the another function: isPalindrome is not a function

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();
};
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

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'));

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda