Tag and build

This commit is contained in:
Angelos Chalaris
2017-12-15 13:53:12 +02:00
parent 5e5cd9faff
commit f6b546c40e
2 changed files with 20 additions and 2 deletions

View File

@ -14,6 +14,7 @@
* [Array difference](#array-difference) * [Array difference](#array-difference)
* [Array includes](#array-includes) * [Array includes](#array-includes)
* [Array intersection](#array-intersection) * [Array intersection](#array-intersection)
* [Array remove](#array-remove)
* [Array sample](#array-sample) * [Array sample](#array-sample)
* [Array union](#array-union) * [Array union](#array-union)
* [Array without](#array-without) * [Array without](#array-without)
@ -129,8 +130,8 @@
Use `Array.concat()` to concatenate an array with any additional arrays and/or values, specified in `args`. Use `Array.concat()` to concatenate an array with any additional arrays and/or values, specified in `args`.
```js ```js
const arrayConcat = (arr, ...args) => arr.concat(...args); const ArrayConcat = (arr, ...args) => [].concat(arr, ...args);
// arrayConcat([1], 2, [3], [[4]]) -> [1,2,3,[4]] // ArrayConcat([1], [1, 2, 3, [4]]) -> [1, 2, 3, [4]]
``` ```
[⬆ back to top](#table-of-contents) [⬆ back to top](#table-of-contents)
@ -170,6 +171,22 @@ const intersection = (a, b) => { const s = new Set(b); return a.filter(x => s.ha
[⬆ back to top](#table-of-contents) [⬆ back to top](#table-of-contents)
### Array remove
Use `Array.filter()` to find array elements that return truthy values and `Array.reduce()` to remove elements using `Array.splice()`.
The `func` is invoked with three arguments (`value, index, array`).
```js
const remove = (arr, func) =>
Array.isArray(arr) ? arr.filter(func).reduce((acc, val) => {
arr.splice(arr.indexOf(val), 1); return acc.concat(val);
}, [])
: [];
//remove([1, 2, 3, 4], n => n % 2 == 0) -> [2, 4]
```
[⬆ back to top](#table-of-contents)
### Array sample ### Array sample
Use `Math.random()` to generate a random number, multiply it with `length` and round it of to the nearest whole number using `Math.floor()`. Use `Math.random()` to generate a random number, multiply it with `length` and round it of to the nearest whole number using `Math.floor()`.

View File

@ -3,6 +3,7 @@ array-concatenation:array
array-difference:array array-difference:array
array-includes:array array-includes:array
array-intersection:array array-intersection:array
array-remove:array
array-sample:array array-sample:array
array-union:array array-union:array
array-without:array array-without:array