Last active
October 30, 2021 14:44
-
-
Save Ciantic/1f50fa66272214c5d07748e5d39441fc to your computer and use it in GitHub Desktop.
Intersection observer steps
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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