Skip to content

Instantly share code, notes, and snippets.

@FlameWolf
Last active November 29, 2023 11:51
Show Gist options
  • Save FlameWolf/8e72372e07f3c052b295b1b0a44e7852 to your computer and use it in GitHub Desktop.
Save FlameWolf/8e72372e07f3c052b295b1b0a44e7852 to your computer and use it in GitHub Desktop.
Get the ratios of consecutive elements from an array
[1, 2, 3, 4, 5].reduce((accumulator, current, index, { [index + 1]: next }) => next ? accumulator.concat(current / next) : accumulator, []); // [ 0.5, 0.6666666666666666, 0.75, 0.8 ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment