As you can see in the subject :
// WIP
var helper = {};
// Count each time an interval occur in values
for (var i = 1; i < p_table.length; i++) {
var d1 = new Date(p_table[i].datetime);
var d2 = new Date(p_table[i - 1].datetime)
var curr_interval_millis = d1 - d2;
var curr_interval_seconds = curr_interval_millis / 1000;
var key = Math.floor(curr_interval_seconds / 10) * 10; // We group by dozen of seconds and then put it back
if (!helper[key]) helper[key] = 1;
else helper[key] += 1;
}
console.log("Count each time an interval occur in values")
console.log(helper);
// Get the interval that occur the most often
var maxKey = -1;
var maxCount = 0;
Object.keys(helper).forEach(key => {
var currMaxCount = helper[key];
if (currMaxCount > maxCount) {
maxKey = key;
maxCount = currMaxCount;
}
});
console.log("max", maxKey, helper[maxKey])
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…