Im using Node.js. (... and underscore.js)
Consider this data structure
var numbers = [ [10, 20] [30, 40] [40, 50] [45, 70] ...
numbers contain arrays that always contain pairs of numbers. Think of these pairs of numbers as βstartβ and βendβ. I want a function that takes numbers as an argument and a loop through its contents, and if the "start" number of the pair overlaps the "end" number of the previous pair, these arrays are combined into one. For instance:
var numbers = [ [10, 20] [19, 40] [40, 60] [70, 80] ]
Becomes as follows:
var numbers = [ [10, 60] // First, second and third array is merged because of overlapping . [70, 80] ]
Actually, I already wrote a function for this, which works great, but feels a little awkward.
I am curious if any javascript master can blind me with an elegant solution =).
source share