Given an array of numbers with length >=3
and length % 3 == 0
[1, 2, 3, 4, ...]
You will split it in sub-arrays of length 3
[[1, 2, 3], [4, 5, ...], [...
And return an array with
- [0] => The amount of cases in the sub-array where all numbers are equal
- [1] => In case all numbers in sub-array are not equal, the amount of cases in the sub-array where only 2 numbers are equal
Example and test cases:
- Input:
[2, 4, 2, 5, 5, 5, 4, 2, 1, 3, 3, 1]
output[1, 2]
This is because
[[2, 4, 2], [5, 5, 5], [4, 2, 1], [3, 3, 1]]
^ ^ ^ ^ ^ ^ ^
equal all equal equal
so 2 equal
and 1 all equal
[3,5,6,5,5,7,6,6,8,7,7,7,3,4,2,4,4,3] => [1, 3]
[3,3,3,4,4,4,5,5,5,6,6,6,5,4,3] => [4, 0]
[3,4,5,6,7,8,9,8,7,6,5,4,3,2,1] => [0, 0]
This is code-golf, so the shortest answer in bytes win.
PD: Apologies for my English.