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.