I thought that it is simple task but unfortunatelly I can not do it properly without too much if'ology.
I have following data structure. I have a "big period" which starts at 1 and ends at 30.Each object represents "good" period which starts at object.start and ends at object.ends. "Bad" periods are between the "good" ones and could be between 1 and first period and last period and 30.
const data = [
{start: 2, end: 4},
{start: 10, end: 15},
{start: 17, end 27}
]
I would like to get new array of "bad" and "good" periods lengths. Each array item represents length of period (bad or good one)
array = [1, 3, 5, 6, 1, 11, 3]
as a result of
[from 1 to 1 (bad period), from 2 to 4 (good period), from 5 to 9(bad period), from 10 to 15(good period), from 16 to 16(bad period), from 17 to 27(good period), from 28 to 30(bad period)]
My main if'ology starts when I check if first object.start is 0 or not and last object.end is 30 or not. How to avoid it?
constarray calleddatawith properties ofstartandendbut what are you trying to do?