Object.values(arr.reduce((acc, n) => {
const date = n.date.split(' ', 1)[0];
(acc[0][date] = acc[0][date] || { id: ++acc[1], date, docs: [] }).docs.push(n);
return acc;
}, [ {}, 0 ])[0])
[...arr.reduce((acc, n) => {
const [ date ] = n.date.match(/\S+/);
acc.set(date, acc.get(date) || { id: -~acc.size, date, docs: [] }).get(date).docs.push(n);
return acc;
}, new Map).values()]
function walk(node) {
if (node) {
console.log(node);
walk(node.next);
}
}
function walk(node) {
while (node) {
console.log(node);
node = node.next;
}
}