DEV Community

Discussion on: JavaScript ES6 one-liners: merge two sorted lists

Collapse
 
sergeis profile image
Sergei

Yep, I tried to remember it, yet had made a basic mistake of assuming that Array.prototype.shift() is O(1), yet it is O(n) in its most common implementations, including the one specified in the ECMAScript 2015 spec. The code would be O(n1+n2) if it used orderedList2[index_of_first_not_yet_merged_element] instead of shift.

Thread Thread
 
therealkevinard profile image
Kevin Ard • Edited

As much as we have to consider big-o, I'm surprised someone hasn't rebuilt pgsql as a wasm 😂

Just... Whatever, batch insert and order by lol

Thread Thread
 
sergeis profile image
Sergei

Hah. An inverse of this?

I actually ported a legacy C code to wasm/emscripten, but source debugging sucks with wasm, so dropped that effort.