Let's say I want to write a function that does this:
input: [1,1,3,3,4,2,2,5,6,6] output: [[1,1],[3,3],[4],[2,2],[5],[6,6]]
It's grouping adjacent elements that are same.
What should the name of this method be? Is there a standard name for this operation?
In [1,1,3,3,4,2,2,5,6,6]
, a thing like [1,1]
is very often referred to as run (as in run-length encoding, see RLE in Scala). I'd therefore call the method groupRuns
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With