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

Community
  • 1
  • 1
mfrachet
  • 8,772
  • 17
  • 55
  • 110

1 Answers1

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)

Per Hornshøj-Schierbeck
  • 15,097
  • 21
  • 80
  • 101