То есть Ваш код очень хороший и правильно работает кроме последнего варианта
console.log(ageMatrix([18, 30, 20, 45, 36, 20, 47, 50])); // [[18, 20, 20], [30, 36], [45, 47, 50]]
console.log(ageMatrix([20, 20, 20, 20, 40, 40, 40, 40])); // [[20, 20, 20, 20], [40, 40, 40, 40]]
console.log(ageMatrix([18, 20, 22, 24])); // [[18, 20, 22, 24]]
console.log(ageMatrix([20, 22, 20, 22, 20, 23, 24, 25, 24, 24, 24]));
[[20,20,20,22],[22,23,24,24],[24,24,25]]
console.log(ageMatrix([20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20])); // [[20,20,20,20],[20,20,20,20],[20,20,20,20]]
console.log(ageMatrix([18, 20, 22, 24, 26, 28, 30, 18, 18]));
|