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

229
Views
How could i get all values out?

Here is the assignment I have. Declare a function getAllValues. You may need to use both kinds of for loops!

/**
* @param {Array} ???
* @returns {Array} an array of all of the values in all of the given objects
*/
function getAllValues(arrayOfObject){ 
    let arr = [];
    for(const e of arrayOfObject){
        let obj = arrayOfObject[e];
        for(const key in obj){ 
            arr.push(obj[key]) ;
        } 
    }
    return arr;
}

// test
test(getAllValues(collection), [1, 2, 3, 3, 4, 100]); // returns []
test(getAllValues(collection.slice(1)), [3, 3, 4, 100]); // returns []

What's wrong with my current code?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Looks like the error is here:

let obj = arrayOfObject[e];  

Here the variable e itself is the object from the array, not an index. So it should be:

let obj = e;
about 4 years ago · Juan Pablo Isaza Report
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!