Skip to content

Instantly share code, notes, and snippets.

@ricealexander
Created March 30, 2021 22:05
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 ricealexander/b053f126c90637c1d1d94cc35bcf19ae to your computer and use it in GitHub Desktop.
Save ricealexander/b053f126c90637c1d1d94cc35bcf19ae to your computer and use it in GitHub Desktop.
Returns an array of all fractions of N
function getFractions (n) {
return Array.from({length}, (_, index) => (index + 1) / n)
}
// Example, all fractions of 16 (1/16, 2/16, 3/16, 4/16...)
getFractions(16) // [0.0625, 0.125, 0.1875, 0.25, 0.3125, 0.375, 0.4375, 0.5, 0.5625, 0.625, 0.6875, 0.75, 0.8125, 0.875, 0.9375, 1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment