I have data being returned from a server that I need to sort into buckets for display.
The data looks like this
Array [
Object {
"name": "1.00",
"value": 17,
},
Object {
"name": "1.01",
"value": 10,
},
Object {
"name": "1.5",
"value": 9,
},
Object {
"name": "1.20",
"value": 8,
},
Object {
"name": "1.30",
"value": 7,
},
Object {
"name": "0.80",
"value": 5,
}
]
For this example, the name is the "size" and the value is number of occurrences in the system. IE: (5 records of size "0.80", 8 records of size "1.20")
The end goal is to have the data sorted like so:
[
{key: 'Under .30', value: 11},
{key: '.30 to .39', value: 3},
{key: '.40 .49', value: 2},
...
...
{key: '.90 to .99', value: 1},
{key: '1.00 to 1.09', value: 3},
{key: '1.10 to 1.19', value: 2},
...
...
{key: '5.00 to 5.09', value: 5},
{key: '5.00 to 5.09', value: 1},
...
{key: 'Over 10', value: 3},
{key: 'Other', value 21}
]
Where the key is the size, and the value is the number of total occurrences for that grouping.
Basically I want to do the following:
- For each row, parse the name into a float
- Determine if there is a range already created for this value based off its name.
- If not, create the range, increment the value by the row value
- If range is already created, increment the value by the row value
I can only really think about statically creating all the arrays ahead of time (0.30 all the way to 10+) which is over 100, and then just looping with if statements again, over 100.
Would be greatly appreciated if anyone can help with this problem, or give me a better idea of how I can tackle this problem!