Split array into 3-size chunks with repeats

Viewed 23

How can I split an array into 3-length arrays? If the length isn't divisible by 3 then add repeats:

E.g. [1, 2, 3, 4, 5] -> [1, 2, 3] and [3, 4, 5] Or [1, 2, 3, 4, 5, 6] -> [1, 2, 3] and [4, 5, 6]

0 Answers
Related