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

272
Visualizações
How can I console log all rest paramaters without using a loop? (Including objects and no toString)

I got a mission that I must do which goes like this:

Write a function that does the following: it will accept any number of arguments and do console.log on all of them. Do not use loops.

Example and expected result:

result:

How am I supposed to do something like that without a loop?

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

use this :

function consoleAll(...args) {
    console.log(...args)
}

consoleAll("hello", 2, {name : "milad"})

/*output -> "hello", 2, {
  name: "milad"
}
*/
about 4 years ago · Juan Pablo Isaza Relatório

0

It's pretty simple but it depends on how you want to use this data you feel? But I suppose you could run an array length and sort your checks some how.

function MyHugeFunction (data) {
  console.log(`Size: ${data.length}`);
  console.log(`First Arg: ${data[0]}`);
  console.log(`Entire Argument Set: ${data}`);
};

MyHugeFunction(["test","hello","123"]);

about 4 years ago · Juan Pablo Isaza Relatório

0

It's not obvious without the context but I think it is an exercise on spread operator.

In this case, your function would be something like

function(...args) {
  args.forEach((val) => console.log(val))
}

or

function(...args) {
  console.log(...args)
}

The "...args" is used to get all the arguments of your function in a "args array" and the forEach function applied to this array does the trick

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