Skip to content

Commit

Permalink
📚 docs(randrange): Add function signature and detailed description.
Browse files Browse the repository at this point in the history
  • Loading branch information
make-github-pseudonymous-again committed Apr 6, 2021
1 parent c78cafe commit 7ff6a37
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/api/randrange.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
import randint from './randint.js';

/**
* Return a randomly selected element from range(start, stop, step).
* Pick an element from range(start, stop, step) uniformly at random.
*
* Return an element from range(start, stop, step) selected uniformly at random.
* If step is positive, this set corresponds to
* {x: x in [start, stop[ AND x % step = 0}.
* If step is negative, the range has to be given in reverse order, that is,
* largest value first, smallest value second. Both the starting value and the
* step value are optional. By default the starting value is <code>0</code>.
* The default for the step value is <code>1</code>.
*
* TODO: Handle empty ranges.
*
* @param {number} [start=0] - The starting value.
* @param {number} stop - The stopping value.
* @param {number} [step=1] - The step value.
* @return {number} The picked element.
*/

const randrange = (start, stop, step) => {
// TODO handle empty ranges

if (stop === undefined) return randint(0, start);
if (step === undefined) step = 1;

Expand Down

0 comments on commit 7ff6a37

Please sign in to comment.