Home > Blockchain >  Difference in time complexity of toString and join of array
Difference in time complexity of toString and join of array

Time:05-04

Is there any difference in time complexity between [1,2,3].toString() and [1,2,3].join() . As I understand time complexity of join function is O(n) . What is the time complexity of .toString() method ?

CodePudding user response:

Both have the same time complexity. Array.prototype.toString calls Array.prototype.join without argument. ',' is the default separator.

MDN Spec

CodePudding user response:

toString() has the same time complexity of join(), the difference is that with join() is possible to choose the separator.

array.join([separator]);

  • Related