Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

194
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda