What is the fastest way to split an array into small chunks, then apply math function in the small array? The math function could be simple such as the total of the chunk mod 26.
What I mean, I have array [1,2,3,4,5,6]
, I need to create chunks of it to have every 3 elements in 1 chunk, so I will get from the main array:
[1,2,3]
[4,5,6]
The apply total of [1,2,3]
6mod26, and [4,5,6]
15mod26.
So, the final array will be [6,15]
.
Also, ignore the remaining of the main array if the remaining elements less the required chunk size, or add it in array alone.
simple way ..
[1,2,3,4,5,6,7] => chunk1[1,2,3] , chunk2[4,5,6] , chunk3[7]
result = [ (total([1,2,3]) mod 26 ) , (total([4,5,6]) mod 26 ) ]
I hope this is clear.