OK, looking at the above link (which I assume is the right one), it looks like you meant JS classes - when I first read that sentence I thought you were saying that this is a school assignment and you were going to work on it in class.
I’m still not clear on a few things. We’re ignoring the “bonus”? And we are guaranteed to not have duplicate dates?
And you still are using map incorrectly. It works but it is semantically incorrect. I mentioned this in the other thread. (Please don’t create multiple threads on the same subject by the way.) You should be using forEach in this case. map creates and returns a new array where each element is based on the corresponding old element. You just want to do something to/with each element. That is forEach.
The other issue I have is that in your sample output, I see this:
3: [ day: {
I don’t understand what the opening square bracket is. Is that the start of an array? Then the “day” shouldn’t be there because arrays don’t take key/value pairs.
That being said, I think classes are overkill here. I took a swipe at this, and I took the full data from your old post, with a spell correction:
const TEST_DATA = [
{ draw_date: '2022-03-16T00:00:00.000', winning_numbers: '34 42 48 51 56 59', bonus: '6' },
{ draw_date: '2022-03-12T00:00:00.000', winning_numbers: '12 19 22 34 50 56', bonus: '7' },
{ draw_date: '2022-03-09T00:00:00.000', winning_numbers: '17 28 29 32 37 40', bonus: '56' },
{ draw_date: '2022-03-05T00:00:00.000', winning_numbers: '01 11 21 38 39 52', bonus: '44' },
{ draw_date: '2022-03-02T00:00:00.000', winning_numbers: '19 20 37 41 47 55', bonus: '31' },
{ draw_date: '2022-02-26T00:00:00.000', winning_numbers: '08 32 43 46 52 58', bonus: '14' },
{ draw_date: '2022-02-23T00:00:00.000', winning_numbers: '13 15 36 46 53 57', bonus: '58' },
]
And I wrote a function and was able to pump it through and get this:
{
'0': {
'2022-03-05': [1],
'2022-02-26': [8]
},
'1': {
'2022-03-12': [12, 19],
'2022-03-09': [17],
'2022-03-05': [11],
'2022-03-02': [19],
'2022-02-23': [13, 15]
},
'2': {
'2022-03-12': [22],
'2022-03-09': [28, 29],
'2022-03-05': [21],
'2022-03-02': [20]
},
'3': {
'2022-03-16': [34],
'2022-03-12': [34],
'2022-03-09': [32, 37],
'2022-03-05': [38, 39],
'2022-03-02': [37],
'2022-02-26': [32],
'2022-02-23': [36]
},
'4': {
'2022-03-16': [42, 48],
'2022-03-09': [40],
'2022-03-02': [41, 47],
'2022-02-26': [43, 46],
'2022-02-23': [46]
},
'5': {
'2022-03-16': [51, 56, 59],
'2022-03-12': [50, 56],
'2022-03-05': [52],
'2022-03-02': [55],
'2022-02-26': [52, 58],
'2022-02-23': [53, 57]
}
}
Is that the shape of data you are after?
This makes some assumptions - the number data will always be a two digit string with a leading 0 if needed, and we don’t care about the order of the numbers in the final array.