can you help me? I have and array named baseArray. As you see some values are same, I tried to remove duplicate values, but not fully worked.
Then I tried to split arrays like
[[1,2,3,4,5,6,7], [1,2,4,5,6,7], [1,2,3,4,5,6,7,8,9,10..]..]
I want to split each number series begin with number 1
const editedArray = [];
const baseArray = [1, 2, 3, 4, 5, 6, 7, 7, 7, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 1,
2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 12, 12, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7,
7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
13, 13, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12,
12, 13, 13, 1, 2, 3, 4, 5, 6, 6, 6, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 1, 2, 3, 4,
5, 6, 7, 8, 9, 10, 10, 10, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10,
10, 1, 2, 3, 4, 5, 6, 6, 6, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 1, 2, 3, 4, 5, 6, 7,
8, 9, 9, 9, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 1, 2, 3, 4, 5, 6,
7, 8, 9, 10, 10, 10, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10,
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 11, 11, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7,
8, 8, 9, 9, 10, 10, 11, 11, 1, 2, 3, 4, 5, 5, 5, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5
]
baseArray.filter(function (item, pos) {
return baseArray.indexOf(item) == pos;
})
baseArray.forEach(item => item === 1 ?
editedArray.push([1]) :
editedArray[editedArray.length - 1].push(item)
)
console.log(editedArray)
This gives me as a result like enter image description here
Updated, It works fine now
const editedArray = [];
const baseArray = [1, 2, 3, 4, 5, 6, 7, 7, 7, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 1,
2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 12, 12, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7,
7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
13, 13, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12,
12, 13, 13, 1, 2, 3, 4, 5, 6, 6, 6, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 1, 2, 3, 4,
5, 6, 7, 8, 9, 10, 10, 10, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10,
10, 1, 2, 3, 4, 5, 6, 6, 6, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 1, 2, 3, 4, 5, 6, 7,
8, 9, 9, 9, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 1, 2, 3, 4, 5, 6,
7, 8, 9, 10, 10, 10, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10,
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 11, 11, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7,
8, 8, 9, 9, 10, 10, 11, 11, 1, 2, 3, 4, 5, 5, 5, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5
]
var result = baseArray.filter((a, i, aa) => a !== aa[i + 1]);
result.forEach(item => item === 1 ?
editedArray.push([1]) :
editedArray[editedArray.length - 1].push(item)
)
console.log(editedArray)