new arrray remove and concat issue fixed

This commit is contained in:
sabareesh
2017-12-15 11:41:51 +05:30
parent 123ca7943f
commit 4e7085b5ba
3 changed files with 15 additions and 2 deletions

View File

@ -10,6 +10,7 @@
## Contents
* [Anagrams of string (with duplicates)](#anagrams-of-string-with-duplicates)
* [Array concatenation](#array-concatenation)
* [Array difference](#array-difference)
* [Array intersection](#array-intersection)
* [Array union](#array-union)
@ -57,7 +58,6 @@
* [Promisify](#promisify)
* [Random integer in range](#random-integer-in-range)
* [Random number in range](#random-number-in-range)
* [Randomize order of array](#randomize-order-of-array)
* [Redirect to url](#redirect-to-url)
* [Remove](#remove)
* [Reverse a string](#reverse-a-string)
@ -97,6 +97,15 @@ const anagrams = str => {
// anagrams('abc') -> ['abc','acb','bac','bca','cab','cba']
```
### Array concatenation
Use `Array.concat()` to concatenate and array with any additional arrays and/or values, specified in `args`.
```js
const ArrayConcat = (arr, ...args) => [].concat(arr, ...args);
// ArrayConcat([1], [1, 2, 3, [4]]) -> [1, 2, 3, [4]]
```
### Array difference
Create a `Set` from `b`, then use `Array.filter()` on `a` to only keep values not contained in `b`.
@ -618,10 +627,12 @@ Remove elements from `arr` that are returns truthy. Use `Array.filter()` to find
```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]
```

View File

@ -3,6 +3,6 @@
Use `Array.concat()` to concatenate and array with any additional arrays and/or values, specified in `args`.
```js
const ArrayConcat = (arr, ...args) => arr.concat(...args);
const ArrayConcat = (arr, ...args) => [].concat(arr, ...args);
// ArrayConcat([1], [1, 2, 3, [4]]) -> [1, 2, 3, [4]]
```

View File

@ -4,9 +4,11 @@ Remove elements from `arr` that are returns truthy. Use `Array.filter()` to find
```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]
```