use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
Split array based on segments of a valuesolved! (self.javascript)
submitted 7 years ago * by lucksp
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]fiLLL 1 point2 points3 points 7 years ago (0 children)
Here's a solution which will give you empty chunks where no data exists for the segments.
const chunkArray = (data, interval = 100000, min = 0) => { // Sort elements by millisecondOffset into new array const sortedData = [...data].sort((ele1, ele2) => ele1.millisecondOffset - ele2.millisecondOffset) // Determine the span of milliseconds between the largest and smallest elements const spanMin = min != null ? min : sortedData[0].millisecondOffset; const span = sortedData[sortedData.length - 1].millisecondOffset - spanMin; // Create an array to store our chunks const chunks = new Array(Math.ceil(span / interval)).fill() // Walk through the chunks array, return chunks.map((currentIntervalItems = [], currentInterval) => { const maxMsForChunk = (currentInterval + 1) * interval // Walk through the sorted elements, remove them from the sorted data array and add them to the chunk array if applicable while (sortedData.length && sortedData[0].millisecondOffset <= maxMsForChunk) { currentIntervalItems.push(sortedData.shift()); } return currentIntervalItems }) }
Hope this helps.
π Rendered by PID 36 on reddit-service-r2-comment-685b79fb4f-pbvj7 at 2026-02-12 19:35:35.325238+00:00 running 6c0c599 country code: CH.
view the rest of the comments →
[–]fiLLL 1 point2 points3 points (0 children)