Last active
January 16, 2023 02:49
-
-
Save imamabdulazis/fe35cc0506555478d0668e738ee786fd to your computer and use it in GitHub Desktop.
Create new react native section List with native JS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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