I have data like the following:
var data = [{
id: 1,
date: new Date("2010-01-01"),
value: 10
}, {
id: 2,
date: new Date("2010-01-01"),
value: 11
}, {
id: 3,
date: new Date("2010-01-01"),
value: 12
}, {
id: 4,
date: new Date("2010-01-02"),
value: 10
}, {
id: 5,
date: new Date("2010-01-03"),
value: 10
}, {
id: 6,
date: new Date("2010-01-03"),
value: 21
}, {
id: 7,
date: new Date("2010-01-03"),
value: 22
}, {
id: 8,
date: new Date("2010-01-03"),
value: 23
}];
I am trying to apply two kinds of filters:
Filter1should give me only those points that differ by 1 in theirvaluefield but having the samedatefield. Therefore, this should return a new dataset containing data records with ids 1,2,3, 6,7,8 (the first three because values are 10,11,12 and last three because values are 21,22,23)Filter2should give me only those points that differ by 1 day in theirdatefield but having the samevaluefield. Therefore, this should return a new dataset containing data records with ids 1,4,5
I am currently doing this in C# on the server-side but am looking to see if there is an efficient way to do this in Javascript. Any suggestions?
Why, custom sort functions, of course!