1

I was wondering what are the complexity (in big O notation) of certain functions of some prototypes (in best AND worst case) in Javascript ? I can't find any document listing these informations concerning :

  • Object.assign

EDIT : All the previous cases are covered in (except Object.assign) What is the performance of Objects/Arrays in JavaScript? (specifically for Google V8)

Can you help me ?

Thanks for your help

5
  • 1
    Possible duplicate of What is the performance of Objects/Arrays in JavaScript? (specifically for Google V8) Commented Jul 11, 2016 at 11:06
  • Thanks for your answer, this way, I just need to know what is the complexity of Object.assign :-) Commented Jul 11, 2016 at 11:07
  • 1
    Object.assign is O(N) :) Commented Jul 11, 2016 at 11:08
  • Thanks for this, I m closing the topic so :). Pass it into answer, so I can upvote your answer :D Commented Jul 11, 2016 at 11:08
  • 1
    I guess the post would be better if i post an argumentation ;) Commented Jul 11, 2016 at 11:19

1 Answer 1

5

Since Object.assign is basically looping an array once and assigning the value to the object, I think it's safe to say the complexity is O(n).

Check out the polyfill version here: https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Object/assign

It DOES show a nested loop, but since only one of the loops is linked to the length of the argument passed, the notation is still O(x*n) => O(n)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.