loading...

re: JavaScript ES6 one-liners: merge two sorted lists VIEW POST

TOP OF THREAD FULL DISCUSSION
re: That's also slower than the original. shift cost O(m) some costs O(m) and reduce Costs O(n) where m is the length of orderedList2 and n the lengt...
 

A very good point about the complexity of shift! I missed that one. some is not as bad, since it quits on first true, and the next loop it continues where it left off, so orderedList2 is scanned at most once in total, not each time. I could not figure out a simple way to maintain the starting index in orderedList2 during the merge, to avoid actually removing elements from it, while keeping the code to a single statement.

Code of Conduct Report abuse