Here are three different options, they might capture incorrect rows due to off-by-one errors
// Option1
Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
// https://leetcode.com/problems/merge-intervals/solutions/3161191/solution/
merge_intervals = function({intervals}, {Default Local},
// Assumes array is sorted by first index
stack = {};
For Each({interval}, intervals,
If(N Items(stack) == 0 | stack[N Items(stack)][2] < interval[1],
Insert Into(stack, Eval List({interval}));
,
stack[N Items(stack)][2] = max(stack[N Items(stack)][2], interval[2]);
);
);
return(stack);
);
r_start = (dt << Get Rows Where(:weight > 120)) + 1;
r_end = r_start + 10;
toohigh = Loc(r_start > N Rows(dt));
r_start[toohigh] = N Rows(dt);
toohigh = Loc(r_end > N Rows(dt));
r_end[toohigh] = N Rows(dt);
rs = As List(r_start || r_end);
res = merge_intervals(rs);
// Option2
Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
r_start = dt << Get Rows Where(:weight > 120);
res2 = dt << get rows where(Any(Row() > r_start & Row() <= r_start + 10));
// Option3
Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
r = As List(dt << Get Rows Where(:weight > 120));
rs = {};
max_rows = N Rows(dt);
For Each({cur_r}, r,
Insert Into(rs, As List(Index(Min(max_rows, cur_r + 1), Min(max_rows, cur_r + 10))));
);
-Jarmo