javascript - Transform the input array to another array of the objects with the same structure -


hi have problem want input array , transform other array based on condition given below :

you given input array of intervals on number axis. each interval, start point, end point , “value” known. write function in pure javascript, transform input array array of objects same structure. function should sum “values” of intersecting intervals , include in result intervals different sum of “values”. see examples of input , expected output. note start , end point coordinates may have fractional values.

here input , desire output:

var input1 = [     { start :1, end :2, value :1 },      { start :2, end :3, value :1 } ];  var output1 = [     { start :1, end : 3, value :1 } ];   var input2 = [     { start :1, end :3, value :1 },      { start :2, end :4, value :1 } ];  var output2 = [     { start :1, end :2, value :1 },      { start :2, end :3, value :2 },      { start :3, end :4, value :1 } ];  var input3 = [     { start :1, end :3, value :1 },      { start :2, end :4, value :1 },      { start :2, end :5, value :2 },      { start :4, end :5, value :1 } ];  var output3 = [     { start :1, end :2, value :1 },      { start :2, end :3, value :4 },      { start :3, end :5, value :3 } ]; 


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

reflection - How to access the object-members of an object declaration in kotlin -

php - Doctrine Query Builder Error on Join: [Syntax Error] line 0, col 87: Error: Expected Literal, got 'JOIN' -