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

394
Views
Promise.allsettled returning undefined

I am trying to use promise all settled and I do console log inside the function it gives correct output. After returning this output from promise.allsettled and while I assert this- it shows undefined. Could you please help on identifying the issue?

Please note developerArr is an array element.code()- code is another function resolving promise which returns a string

`console.log("promise all settled ", output, typeof(output))` shows
***promise all settled  console.log("Hello, Nicole!")
System.out.println("Hello, John!")
print("Hello, Pete!") string***

    export default function hackathon(developerArr) {
    //let strMsg = ""
    let output = []
    let promises = []
    let i = 0
   
    developerArr.forEach(element => {
        promises[i] = new Promise((resolve) => {
            resolve(element.code())
        })
        i ++
    })

    Promise.allSettled(promises).then((results) => {
        results.forEach((result) => {
            if (result.value) {
                output.push(result.value)
            }else if (result.reason) {
                output.push(result.reason)
            }
        })
        output = output.join('\n')
        console.log("promise all settled ", output, typeof(output))
        return output.toString()
    })
}


 

    it('should resolve with an error message for an unknown language', async () => {
    const output = await hackathon([
      ...developers,
      new Developer({
        name: 'Adam',
        language: 'abap'
      })
    ])
    var str = [
      'console.log("Hello, Nicole!")',
      'System.out.println("Hello, John!")',
      'print("Hello, Pete!")',
      'Unsupported language: abap'
    ].join('\n')
    console.log(str, typeof(str))
    console.log("output from hack test.js",output, typeof(output))
    
    assert.equal(output, [
      'console.log("Hello, Nicole!")',
      'System.out.println("Hello, John!")',
      'print("Hello, Pete!")',
      'Unsupported language: abap'
    ].join('\n'))
  })
})

`console.log("output from hack test.js",output, typeof(output))` shows 
***output from hack test.js undefined undefined***
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!