Skip to content

Instantly share code, notes, and snippets.

@Ciantic
Last active October 30, 2021 14:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ciantic/1f50fa66272214c5d07748e5d39441fc to your computer and use it in GitHub Desktop.
Save Ciantic/1f50fa66272214c5d07748e5d39441fc to your computer and use it in GitHub Desktop.
Intersection observer steps
// steps(10) == [0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0] == length = 11
const steps = (r) => Array(r + 1).fill().map((_, i) => i / r); // with fill
const steps = (r) => ([...Array(r + 1)]).map((_, i) => i / r); // with splat
const steps = (r) => Array.apply(null, Array(r + 1)).map((_, i) => i / r); // If no splat
// Benchmark notes: third implementation fails with maximum stack size, first one is the fastest (with fill)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment