Skip to content

Commit 01544db

Browse files
AndrewLipscombmattbaileyuk
authored andcommitted
Reflect missing behaviours on map in docs
1 parent d1958d0 commit 01544db

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

docs/higher-order-functions.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,31 @@ sidebar_label: Higher Order Functions
77
## `$map()`
88
__Signature:__ `$map(array, function)`
99

10-
Returns an array containing the results of applying the `function` parameter to each value in the `array` parameter.
10+
If the input argument is an array of 2 or more elements, returns an array containing the results of applying the `function` parameter to each value in the `array` parameter.
11+
12+
```
13+
$map([1,2,3], function($v) { $v * 2 })
14+
```
15+
16+
evaluates to
17+
18+
```
19+
[ 2, 4, 6 ]
20+
```
21+
22+
If the input argument is an array with 1 element, returns the single result of applying the `function` parameter to each value in the `array` parameter.
23+
24+
```
25+
$map([2], function($v) { $v * 2 })
26+
```
27+
28+
evaluates to
29+
30+
```
31+
4
32+
```
33+
34+
If the input argument is an empty array, returns `undefined`
1135

1236
The function that is supplied as the second parameter must have the following signature:
1337

0 commit comments

Comments
 (0)