Merge/flatten an array of arrays

You can use concat to merge arrays:  Run code snippetExpand snippet Using the apply method of concat will just take the second parameter as an array, so the last line is identical to this: There is also the Array.prototype.flat() method (introduced in ES2019) which you could use to flatten the arrays, although it is only available in Node.js starting with version 11, and not … Read more

How to make a flat list out of a list of lists

Given a list of lists t, which means: is faster than the shortcuts posted so far. (t is the list to flatten.) Here is the corresponding function: As evidence, you can use the timeit module in the standard library: Explanation: the shortcuts based on + (including the implied use in sum) are, of necessity, O(T**2) when there are T sublists — as the intermediate … Read more