I would recommend outputting a collection, rather than an object because it will be easier to work with; since it's an array of objects you can filter, map, and reduce, which you can't do very comfortably on objects. For example:
function getStepRanges(ranges, times) {
return ranges.map(function(range) {
var ranges = range.split(/[-+]/)
var min = +ranges[0]
var max = +ranges[1] || Infinity
return times.reduce(function(acc, x) {
// Note that your range is not inclusive
// you may want to do "x >= min" instead
if (x > min && x <= max) {
acc.range = range
acc.values = (acc.values||[]).concat(x)
}
return acc
},{})
})
}
Using it on this dummy data:
var times = [1,2,3,4,5,10,11,12,13,14,21,23,24,25,26,31,32,33,34,35,41,42,43,44,45,51,52,53,54,55,61,62,63]
var ranges = ['0-10', '11-20', '21-30', '31-40', '41-50', '51-60', '61+']
It will return this collection:
[ { range: '0-10', values: [ 1, 2, 3, 4, 5, 10 ] },
{ range: '11-20', values: [ 12, 13, 14 ] },
{ range: '21-30', values: [ 23, 24, 25, 26 ] },
{ range: '31-40', values: [ 32, 33, 34, 35 ] },
{ range: '41-50', values: [ 42, 43, 44, 45 ] },
{ range: '51-60', values: [ 52, 53, 54, 55 ] },
{ range: '61+', values: [ 62, 63 ] } ]
With that data then you can do what you need, for example getting the maximum values:
var result = getStepRanges(ranges, times)
// Easy, we have a collection!
// but careful, it mutates the original object
// you may want to use an "extend" helper to clone it first
var maxRanges = result.map(function(x) {
x.max = Math.max.apply(0, x.values)
return x
})
console.log(maxRanges)
/*[ { range: '0-10', values: [ 1, 2, 3, 4, 5, 10 ], max: 10 },
{ range: '11-20', values: [ 12, 13, 14 ], max: 14 },
{ range: '21-30', values: [ 23, 24, 25, 26 ], max: 26 },
{ range: '31-40', values: [ 32, 33, 34, 35 ], max: 35 },
{ range: '41-50', values: [ 42, 43, 44, 45 ], max: 45 },
{ range: '51-60', values: [ 52, 53, 54, 55 ], max: 55 },
{ range: '61+', values: [ 62, 63 ], max: 63 } ]*/
[[0, 10], [11, 20], [21, 30], [31, 40], [41, 50], [51, 60], [61, Number.POSITIVE_INFINITY]][{min: 0, max: 10, label: '0-10'}, ...])