Travis build: 1968

This commit is contained in:
30secondsofcode
2018-04-16 14:53:39 +00:00
parent 0f28ce5212
commit 9ea87f5ebe
13 changed files with 51 additions and 15 deletions

View File

@ -133,6 +133,7 @@ average(1, 2, 3);
* [`initializeArrayWithRange`](#initializearraywithrange) * [`initializeArrayWithRange`](#initializearraywithrange)
* [`initializeArrayWithRangeRight`](#initializearraywithrangeright) * [`initializeArrayWithRangeRight`](#initializearraywithrangeright)
* [`initializeArrayWithValues`](#initializearraywithvalues) * [`initializeArrayWithValues`](#initializearraywithvalues)
* [`initializeNDArray`](#initializendarray)
* [`intersection`](#intersection) * [`intersection`](#intersection)
* [`intersectionBy`](#intersectionby) * [`intersectionBy`](#intersectionby)
* [`intersectionWith`](#intersectionwith) * [`intersectionWith`](#intersectionwith)
@ -1527,6 +1528,33 @@ initializeArrayWithValues(5, 2); // [2,2,2,2,2]
<br>[⬆ Back to top](#table-of-contents) <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 ### intersection
Returns a list of elements that exist in both arrays. 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

View File

@ -7,7 +7,9 @@ Use `Array.map()` to generate rows where each is a new array initialized using `
```js ```js
const initializeNDArray = (val, ...args) => 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 ```js