Travis build: 1968

This commit is contained in:
30secondsofcode
2018-04-16 14:53:39 +00:00
parent 846ad495c4
commit 3daaa5c3f6
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

@ -6,11 +6,13 @@ Use recursion.
Use `Array.map()` to generate rows where each is a new array initialized using `initializeNDArray`. Use `Array.map()` to generate rows where each is a new array initialized using `initializeNDArray`.
```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
initializeNDArray(1,3); // [1,1,1] initializeNDArray(1, 3); // [1,1,1]
initializeNDArray(5,2,2,2); // [[[5,5],[5,5]],[[5,5],[5,5]]] initializeNDArray(5, 2, 2, 2); // [[[5,5],[5,5]],[[5,5],[5,5]]]
``` ```