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

367
Visualizações
Why is array.includes() always returning false in React Typescript with useReducer Hook?

Asked the question earlier today, thinking it was a problem that needed async to work, was advised that includes() doesn't need an async implementation and was recommended that I ask again. So, here we go,

I am using .includes() method to check if a word is valid, by checking for inclusion on a 12,000 element or so array. The method always returns false. I've tried to isolate the bug with no success. Perhaps someone can spot an obvious typo or bug I've just over looked? I will include the interfaces at the bottom in case those are helpful.

//helpers.ts
// I have checked to make sure the word is valid, including casing, it doesn't work, even if I pass it a string literal.
export function validateGuess(guess: GuessCharacter[]) {
  let word: string = '';

  for (let character of guess) {
    word += character.value;
  }
 
  return allWords.includes(word);
}

it is called in my reducer

//gameStateReducer.ts
...
case ActionKind.Enter: {
      if (guesses[guessCount][4].value === ' ') {
        console.log('Not enough letters');
        return gameState;
      }

      if (!validateGuess(guesses[guessCount])) {
        console.log('Not in word list');
        return gameState;
      }

      //continues process and returns updated state
      ...
    }

which is called by the event handler

//index.ts, modified, I actually pass a whole object but it's a little verbose for the post/issue
  function handleEnterPress() {
    dispatch(keyAction.Enter);
  }

which is the callback in this component

//Keyboard.tsx
<button className="enter-button" onClick={handleEnterPress}>
  ENTER
</button>
interface GuessCharacter {
  value: string;
  place: number; //zero-indexed
  correctValue: boolean;
  correctPlace: boolean;
  submitted: boolean;
}

interface GameState {
  solution: string;
  guesses: GuessCharacter[][];
  guessCount: number; //zero-indexed
  characterBank: KeyboardCharacter[];
}

Thanks, my apologies if there is an assumption that I left unstated, I have reread the post and hope my question is good to go.

about 4 years ago · Juan Pablo Isaza
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