Let's say we have an array structured like this:
let arr = [{
name: "Peter"
}, {
name: "Peter"
}, {
name: "John"
}, {
name: "Peter"
}, {
name: "Sarah"
}, {
name: "John"
}]
The goal is to transform it into a new array that groups the duplicates together like this:
let dupArray = [
[{
name: "Peter"
}, {
name: "Peter"
}, {
name: "Peter"
}],
[{
name: "John"
}, {
name: "John"
}],
[{
name: "Sarah"
}]
]
This process focuses on creating a new array by grouping the duplicate elements, not simply duplicating them.