[1, 2, 1, 2, 3, 1, 1, 2, 3]
[[1, 2], [1, 2, 3], [1], [1, 2, 3]]
var a = [1, 2, 1, 2, 3, 1, 1, 2, 3];
var d = {};
a.forEach(function(value){
if(typeof d[value] == 'undefined')
d[value] = [];
d[value].push(value);
});
console.log(d);
1: (4) [1, 1, 1, 1]
2: (3) [2, 2, 2]
3: (2) [3, 3]
arr.reduce((acc, n, i) => (
(!i || n === 1) && acc.push([]),
acc[acc.length - 1].push(n),
acc
), [])
const a = [1, 2, 1, 2, 3, 1, 1, 2, 3];
const d = [];
for (let i = 0; i < a.length; i++) {
a[i] === 1 ? d.push([1]) : d[d.length - 1].push(a[i]);
}
console.log(d); // [ [ 1, 2 ], [ 1, 2, 3 ], [ 1 ], [ 1, 2, 3 ] ]
const a = [1, 2, 1, 2, 3, 1, 1, 2, 3];
const d = [];
a.map(el => {
el === 1 ? d.push([1]) : d[d.length - 1].push(el);
});
console.log(d);