Array.unshift() is O(n) per call because it shifts all existing elements. In a loop building an n-element array, this makes the total cost O(n²). Replace with push() + reverse() which is O(n) total. Produces the identical message ordering.
Array.unshift() is O(n) per call because it shifts all existing elements. In a loop building an n-element array, this makes the total cost O(n²). Replace with push() + reverse() which is O(n) total. Produces the identical message ordering.