Data manipulation for grouping different keys?

So I want to group the numbers in ‘winning_numbers’
LINK OF CODE: ‘’ Manipulating Obj - Replit ‘’

const obj = [{ 0, 10, 20, 30, 40, 50 }]

and if the number is in range of the key then I will added to that key with the date and an array of the numbers of the range of the key

the keys 0, 50 are fine but the others are overlapping. The filter is remembering the older and new keys.

const 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"}
]

const groupNumber = {}
const keys = Array.from({length: 6}, (_,y) => (y * 10))
keys.map(key => groupNumber[key] = [])

data.map( d => {
  // we get the numbers and days
  let nums = d['winning_numbers']
  let days  = d['draw_date']
  getNumbers(days, nums)
})

function getNumbers(day, nums){
  // go to all the keys and push the day and the array to that key if is in the ran
  for(const [key,val] of Object.entries(groupNumber)){ 
    let days = {}
    
    // get the specific range of numbers from the key
    days[day] = nums.split(' ').filter( d => (+d >= key && +d < key+10)   )
    groupNumber[key].push(days)
  }
}

First of all, can you show us what you want the final data to look like? That is not clear to me. Are you just looking for a histogram of numbers?

Also, I’d say that you are misusing the map method here. The callback should return a value that is stored in the new array to be returned by the method. It looks like you are just using it like a forEach.

Sorry, I created a new thread for it to make it more clear