I'm trying to group my JavaScript array of objects by two attributes of the object contained between a range of 2 numbers, (in this case between start and start+2) this means every 2 seconds and then concat the content in an array.
var myArray = [
{
start: 1.1,
end: 1.6,
content: "you"
},
{
start: 1.8,
end: 2.1,
content: "should"
},
{
start: 2.2,
end: 2.5,
content: "not"
},
{
start: 2.9,
end: 3.1,
content: "be"
},
{
start: 3.6,
end: 4.0,
content: "here"
},
{
start: 4.5,
end: 5.0,
content: "please"
},
{
start: 5.2,
end: 5.8,
content: "go"
},
{
start: 5.9,
end: 6.3,
content: "away"
}
];
The idea is try to get this, note the max separation is between 2 secs.
var final = [
{
startArray: [1.1, 1.8, 2.2, 2.9],
endArray: [1.6, 2.1, 2.5, 3.1],
start: 1.1,
end: 3.1,
content: ["you", "should", "not", "be"]
},
{
startArray: [3.6, 4.5],
endArray: [4.0, 5.0],
start: 3.6,
end: 5.0,
content: ["here","please"]
},
{
startArray: [5.2, 5.9],
endArray: [5.8, 6.3],
start: 5.2,
end: 6.3,
content: ["go","away"]
}
];
How should I approach this problem? help :( !.
startof the first element in the group andendof the last?startandendare like time indicators