Skip to content

Instantly share code, notes, and snippets.

@balintsera
Last active August 12, 2017 06:23
Show Gist options
  • Save balintsera/7b1b71ab54020ebfa047bfd6397de6fe to your computer and use it in GitHub Desktop.
Save balintsera/7b1b71ab54020ebfa047bfd6397de6fe to your computer and use it in GitHub Desktop.
Functional interpolation
const cols = [{ ts: 1 }, { ts: 5 }, { ts: 6 }]
const smallest = 1
const interpolatedCols = cols.reduce((accumulated, current) => {
const prev = accumulated[accumulated.length - 1]
for (let i = prev.ts + smallest; i <= current.ts; i += smallest) {
const element = { ts: i }
accumulated.push(element)
}
return accumulated
}, [cols[0]])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment