Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

196
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!