我有一个排序的 JavaScript 映射结构,它根据时间存储对象状态。
Map(key:time(inMilli), value: {object attributes})
我需要完成的是能够根据开始时间和结束时间检查地图,以获取所有值的集合,而无需遍历整个地图。
//currently using something like this. But would like to not compare against entire map of times
let map = dataService.getTimeData()//returns map of all objects
let updates = getRange(someTime, someTime);
function getRange(start, stop){
let foundValues = [];
//if start is end or after end time
if(start >== stop)return [start];
//search map for values
for([key,value] of map){
if(key > start && key < stop)foundValues.push(key)
}
return foundValues;
}