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

182
Visualizações
What are the advantages of immutable data?

What are the advantages of using immutable libraries like immer.js or immutable.js? What is the difference between making changes to a draft of an object or making changes to a duplicate of the object?

Are there any performance differences (And why?) between the blocks of code below?

Edit: Changed the console.log order and the use the spread operator in the second block of code in response to vanowm comment.

const { produce } = require("immer");

let numArray = [1,2,3];

const nextState = produce(numArray, (draft) => {
  draft.push(4);
});

console.log(nextState); // [ 1, 2, 3, 4 ]
console.log(numArray); // [ 1, 2, 3 ]
let numArray = [1,2,3];

const nextState = ((array) => {
  let newArray = [...array]
  newArray.push(4);
  return newArray;
});

console.log(nextState(numArray)); // [ 1, 2, 3, 4 ]
console.log(numArray); // [ 1, 2, 3 ]
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