Travis build: 1968
This commit is contained in:
28
README.md
28
README.md
@ -133,6 +133,7 @@ average(1, 2, 3);
|
||||
* [`initializeArrayWithRange`](#initializearraywithrange)
|
||||
* [`initializeArrayWithRangeRight`](#initializearraywithrangeright)
|
||||
* [`initializeArrayWithValues`](#initializearraywithvalues)
|
||||
* [`initializeNDArray`](#initializendarray)
|
||||
* [`intersection`](#intersection)
|
||||
* [`intersectionBy`](#intersectionby)
|
||||
* [`intersectionWith`](#intersectionwith)
|
||||
@ -1527,6 +1528,33 @@ initializeArrayWithValues(5, 2); // [2,2,2,2,2]
|
||||
<br>[⬆ Back to top](#table-of-contents)
|
||||
|
||||
|
||||
### initializeNDArray
|
||||
|
||||
Create a n-dimensional array with given value.
|
||||
|
||||
Use recursion.
|
||||
Use `Array.map()` to generate rows where each is a new array initialized using `initializeNDArray`.
|
||||
|
||||
```js
|
||||
const initializeNDArray = (val, ...args) =>
|
||||
args.length === 0
|
||||
? val
|
||||
: Array.from({ length: args[0] }).map(() => initializeNDArray(val, ...args.slice(1)));
|
||||
```
|
||||
|
||||
<details>
|
||||
<summary>Examples</summary>
|
||||
|
||||
```js
|
||||
initializeNDArray(1, 3); // [1,1,1]
|
||||
initializeNDArray(5, 2, 2, 2); // [[[5,5],[5,5]],[[5,5],[5,5]]]
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
<br>[⬆ Back to top](#table-of-contents)
|
||||
|
||||
|
||||
### intersection
|
||||
|
||||
Returns a list of elements that exist in both arrays.
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -7,7 +7,9 @@ Use `Array.map()` to generate rows where each is a new array initialized using `
|
||||
|
||||
```js
|
||||
const initializeNDArray = (val, ...args) =>
|
||||
args.length === 0 ? val : Array.from({ length: args[0] }).map(() => initializeNDArray(val, ...args.slice(1)));
|
||||
args.length === 0
|
||||
? val
|
||||
: Array.from({ length: args[0] }).map(() => initializeNDArray(val, ...args.slice(1)));
|
||||
```
|
||||
|
||||
```js
|
||||
|
||||
Reference in New Issue
Block a user