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

197
Visualizações
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 à 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