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

198
Visualizações
array.some() returns unexpected true

I have this lines of code

const countryIds = intersectingBbox.split(';');
const countryFound = countryIds.some(async (id) => {
     const possibleCountry = await _inBbox(id);
     return _checkPointInPolygonAndDispatch(possibleCountry);
});

This _checkPointInPolygonAndDispatch() is a rather complicated function, but in the end it returns true or false. The some() runs twice. The first iteration it goes into the block of _checkPointInPolygonAndDispatch() where it returns false. The second time it goes into the block of _checkPointInPolygonAndDispatch() where it returns false, and then it breaks the iteration. Logging countryFound gives me a true. This is unexpected because in this function _checkPointInPolygonAndDispatch() it always goes into the block, where it returns false. I rewrote the whole thing to this

const countryIds = intersectingBbox.split(';');
for (let index = 0; index < countryIds.length; index++) {
    const possibleCountry = await _inBbox(countryIds[index]);
    const countryFound = _checkPointInPolygonAndDispatch(possibleCountry)
    if (countryFound) {
        break;
    }
}

And this works as expected.

So I am assuming, I missunderstand some()? I thought it runs as long as something evaluates to true?!

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

your async function is returning a Promise which is truthy. you will have to restructure your code to handle the promises.

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