Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7ff6a37

Browse filesBrowse files
📚 docs(randrange): Add function signature and detailed description.
1 parent c78cafe commit 7ff6a37
Copy full SHA for 7ff6a37

File tree

1 file changed

+16
-4
lines changed
Filter options

1 file changed

+16
-4
lines changed

‎src/api/randrange.js

Copy file name to clipboardExpand all lines: src/api/randrange.js
+16-4Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,24 @@
11
import randint from './randint.js';
22

33
/**
4-
* Return a randomly selected element from range(start, stop, step).
4+
* Pick an element from range(start, stop, step) uniformly at random.
5+
*
6+
* Return an element from range(start, stop, step) selected uniformly at random.
7+
* If step is positive, this set corresponds to
8+
* {x: x in [start, stop[ AND x % step = 0}.
9+
* If step is negative, the range has to be given in reverse order, that is,
10+
* largest value first, smallest value second. Both the starting value and the
11+
* step value are optional. By default the starting value is <code>0</code>.
12+
* The default for the step value is <code>1</code>.
13+
*
14+
* TODO: Handle empty ranges.
15+
*
16+
* @param {number} [start=0] - The starting value.
17+
* @param {number} stop - The stopping value.
18+
* @param {number} [step=1] - The step value.
19+
* @return {number} The picked element.
520
*/
6-
721
const randrange = (start, stop, step) => {
8-
// TODO handle empty ranges
9-
1022
if (stop === undefined) return randint(0, start);
1123
if (step === undefined) step = 1;
1224

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.