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

203
Vistas
Iterating through array of functions NOT being called properly?

I am trying to iterate through an array of functions that return an object with a boolean property used to stop iteration through the array (if false) and return the reason.

However I cannot get my claimCheck to fail even when I make each function return allowed : false ??

Am I calling these properly in claimTests.forEach ?? Not sure what I'm doing wrong??

TEST FUNCTIONS

async function allowedArea() {

  let allowed = false

  if (allowed == false) {
    return { allowed: false, reason: "Area blocked" }
  }

  return { allowed: true, reason: "pass" }
}



async function validSubscription() {
  let allowed = false   // will be an await in the future

  if (allowed == false) {
    return { allowed: false, reason: "Bad Subscription" }
  }
  return { allowed: true, reason: "pass" }
}

Iterate through array containing the test functions

  • stop execution if allowed : false & return the reason.
const claimCheck = async (user, claimCoords) => {

  let result 

  let claimTests = [allowedArea, validSubscription]

  claimTests.forEach(function (func) {
    result = func() // run your function
    if (result.allowed == false) {
      return { allowed: false, reason: result.reason }
    }
  })

  // If ALL functions pass (allowed: true)
  return { allowed: true }
}

// calling in another file
module.exports = claimCheck

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