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

209
Visualizações
What JS feature allows this to run on StackOverflow Snippet but not node

The following code will execute properly in the sandbox:

const concatR = function(arr, ...args) {
    let arr2 = (unnest = elem => !Array.isArray(elem) ? elem : elem.flatMap(unnest))(args);
    return arr.concat(arr2);
};
let x2 = concatR([1,2,3], 'hello', 'new', [1,2,3], [1,2,[3,4]]);
console.log(x2);

However, on my VS Code with Node.js v14.18.0, it gives an error:

ReferenceError: unnest is not defined

Is there a certain feature that (I think?) allows a variable definition to pass a named arrow function, or what feature exists in the code sandbox that isn't on my local machine? Locally, I have to separate the statements:

const concatR = function(arr, ...args) {
    const unnest = elem => !Array.isArray(elem) ? elem : elem.flatMap(unnest);
    let arr2 = unnest(args);
    return arr.concat(arr2);
};
let x2 = concatR([1,2,3], 'hello', 'new', [1,2,3], [1,2,[3,4]]);
console.log(x2);

about 4 years ago · Juan Pablo Isaza
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