mfrachet
mfrachet

Reputation: 8932

Javascript and function complexity

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 :

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

Upvotes: 1

Views: 2699

Answers (1)

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)

Upvotes: 5

Related Questions