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

236
Visualizações
Time Complexity of a simple spreaded array chained with .map() in Javascript?

For example,

const arr = [1,2,3]
let multipliedByTwos = [...arr].map(n=>n*2)

I'm wondering what's the time complexity to produce multipledByTwos.

I know spreading [...arr] is O(N), and .map() in this case is also O(N). But what if they're chained together like the code example above? I assume still O(N)? Because it spreads first (O(N)) and then maps it (O(N)).

Something like this O(N) + O(N) === 2O(N), which really is just O(N). Is this correct? Or should it be O(N^2) because the chaining actually multiplies the time complexity rather than adding them? I'm kinda lost a bit in this concept.

EDIT: Im not asking whether O(N) * 2 is O(N). But im asking about my general understanding of the chaining of [...arr] and .map().

Thanks.

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