Aggregate function that returns an array condtionally

I’m trying to create an aggregate function that returns an array.

Data:
ts value
1621054841952 1
1621054841953 3
1621054841954 4
1621054841955 7
1621054841956 8
1621054841957 14
1621054841958 17

The function takes an input called diffference and returns an array grouped by time. E.g in the above data, if the difference is 3 then the array returns results with a minimum difference between consecutive elements as 3, which is [1,4,7,14,17]

Below is the function that I created but it’s throwing error. I’m trying to find a syntax to conditionally push new values into the array in my accumulator function. Thanks in advance for the assistance!

mindiff = (tables=<-, diff) =>
tables
|> reduce(
// Define the initial accumulator record
identity: {
values: ,
next:0,
},
fn: (r, accumulator) => {
if r.value >= accumulator.next then accumulator.values.push(r.value) and accumulator.next = r.value + diff
}
)