I'm attempting to create subarrays within an array that contains groupings of like numbers. I'm coding in JavaScript.
My array is [1,2,4,591,392,391,2,5,10,2,1,1,1,20,20];
I've sorted the array so its numbers are in order, I figured it would be easier to work with.Below is a visual of what I want to accomplish.
Example:
array = [ 1, 1, 1, 1, 2, 2, 2, 4, 5, 10, 20, 20, 391, 392, 591 ];
output: [[1,1,1,1], [2,2,2],4,5,10,[20,20],391,392,591];
Thank you to anyone able to help!