1 |
|
2 |
|
3 | # Function map
|
4 |
|
5 | Create a new matrix or array with the results of the callback function executed on
|
6 | each entry of the matrix/array.
|
7 |
|
8 |
|
9 | ## Syntax
|
10 |
|
11 | ```js
|
12 | math.map(x, callback)
|
13 | ```
|
14 |
|
15 | ### Parameters
|
16 |
|
17 | Parameter | Type | Description
|
18 | --------- | ---- | -----------
|
19 | `x` | Matrix | Array | The matrix to iterate on.
|
20 | `callback` | Function | The callback method is invoked with three parameters: the value of the element, the index of the element, and the matrix being traversed.
|
21 |
|
22 | ### Returns
|
23 |
|
24 | Type | Description
|
25 | ---- | -----------
|
26 | Matrix | array | Transformed map of x
|
27 |
|
28 |
|
29 | ## Examples
|
30 |
|
31 | ```js
|
32 | math.map([1, 2, 3], function(value) {
|
33 | return value * value
|
34 | }) // returns [1, 4, 9]
|
35 | ```
|
36 |
|
37 |
|
38 | ## See also
|
39 |
|
40 | [filter](filter.md),
|
41 | [forEach](forEach.md),
|
42 | [sort](sort.md)
|