Tag and build
This commit is contained in:
21
README.md
21
README.md
@ -14,6 +14,7 @@
|
||||
* [Array difference](#array-difference)
|
||||
* [Array includes](#array-includes)
|
||||
* [Array intersection](#array-intersection)
|
||||
* [Array remove](#array-remove)
|
||||
* [Array sample](#array-sample)
|
||||
* [Array union](#array-union)
|
||||
* [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`.
|
||||
|
||||
```js
|
||||
const arrayConcat = (arr, ...args) => arr.concat(...args);
|
||||
// arrayConcat([1], 2, [3], [[4]]) -> [1,2,3,[4]]
|
||||
const ArrayConcat = (arr, ...args) => [].concat(arr, ...args);
|
||||
// ArrayConcat([1], [1, 2, 3, [4]]) -> [1, 2, 3, [4]]
|
||||
```
|
||||
|
||||
[⬆ 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)
|
||||
|
||||
### 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
|
||||
|
||||
Use `Math.random()` to generate a random number, multiply it with `length` and round it of to the nearest whole number using `Math.floor()`.
|
||||
|
||||
@ -3,6 +3,7 @@ array-concatenation:array
|
||||
array-difference:array
|
||||
array-includes:array
|
||||
array-intersection:array
|
||||
array-remove:array
|
||||
array-sample:array
|
||||
array-union:array
|
||||
array-without:array
|
||||
|
||||
Reference in New Issue
Block a user