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

230
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
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