Learnt a lot though. Appending to arrays can be really expensive, in spurts. Most JS engines (v8 for eg.) will grow the array size in batches. So, if you keep appending to an array, at certain points, it looks like v8 will have to reallocate new contiguous memory for the array, and copy over the old values to the new location. So, every once in a while, .push-ing to an array will be O(n), where you'd expect it to be O(1).

Since this happens for large arrays, n is usually large when it hits you with the O(n) operation, making things extra slow when you need the perf.