Skip to content
Advertisement

Fastest way to split a list into a list of lists based on another list of lists

Say I have a list that contains 5 unique integers in the range of 0 to 9.

JavaScript

I also have a list of lists, which is obtained by splitting integers from 0 to 19 into 6 groups:

JavaScript

Now I want to split lst based on the reference partitions. For example, if I have

JavaScript

I expect the output to be a list of lists like this:

JavaScript

I want the algorithm to be as fast as possible. Any suggestions?

Advertisement

Answer

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement