Skip to content

Instantly share code, notes, and snippets.

@imamabdulazis
Last active January 16, 2023 02:49
Show Gist options
  • Select an option

  • Save imamabdulazis/fe35cc0506555478d0668e738ee786fd to your computer and use it in GitHub Desktop.

Select an option

Save imamabdulazis/fe35cc0506555478d0668e738ee786fd to your computer and use it in GitHub Desktop.
Create new react native section List with native JS
const input = [
{
"id": 1,
"title": "Apple Store",
"date": "2021-09-10",
"amount": "$100.00",
},
{
"id": 41,
"title": "Zulauf, Walter and Metz",
"date": "2021-09-10",
"amount": "$14.00",
},
{
"id": 9,
"title": "Aufderhar PLC",
"date": "2021-09-09",
"amount": "$78.00",
},
{
"id": 10,
"title": "Bayer and Sons",
"date": "2021-09-07",
"amount": "$67.00",
}
]
const result = input.reduce((accum, current)=> {
let dateGroup = accum.find(x => x.date === current.date);
if(!dateGroup) {
dateGroup = { date: current.date, transactions: [] }
accum.push(dateGroup);
}
dateGroup.transactions.push(current);
return accum;
}, []);
console.log(result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment