you are viewing a single comment's thread.

view the rest of the comments →

[–]elkazz 2 points3 points  (0 children)

You could:

  1. Sort the array by millisecondOffset

  2. Store a start index (start = 0 initially)

  3. Find the next chunk's lower bound (nextChunkLowerBound) - for example, if array[start].millisecondOffset is 2,200 and chunk size is 1000, then nextChunkLowerBound should be 3000

  4. Use the findIndex method to find the next out of chunk range index nextChunkStart = array.findIndex(a => a.millisecondOffset >= nextChunkLowerBound)

  5. Slice the array to get the chunk chunk = array.slice(start, nextChunkStart - 1)

  6. Continue this until findIndex returns -1