new arrray remove and concat issue fixed
This commit is contained in:
13
README.md
13
README.md
@ -10,6 +10,7 @@
|
|||||||
## Contents
|
## Contents
|
||||||
|
|
||||||
* [Anagrams of string (with duplicates)](#anagrams-of-string-with-duplicates)
|
* [Anagrams of string (with duplicates)](#anagrams-of-string-with-duplicates)
|
||||||
|
* [Array concatenation](#array-concatenation)
|
||||||
* [Array difference](#array-difference)
|
* [Array difference](#array-difference)
|
||||||
* [Array intersection](#array-intersection)
|
* [Array intersection](#array-intersection)
|
||||||
* [Array union](#array-union)
|
* [Array union](#array-union)
|
||||||
@ -57,7 +58,6 @@
|
|||||||
* [Promisify](#promisify)
|
* [Promisify](#promisify)
|
||||||
* [Random integer in range](#random-integer-in-range)
|
* [Random integer in range](#random-integer-in-range)
|
||||||
* [Random number in range](#random-number-in-range)
|
* [Random number in range](#random-number-in-range)
|
||||||
* [Randomize order of array](#randomize-order-of-array)
|
|
||||||
* [Redirect to url](#redirect-to-url)
|
* [Redirect to url](#redirect-to-url)
|
||||||
* [Remove](#remove)
|
* [Remove](#remove)
|
||||||
* [Reverse a string](#reverse-a-string)
|
* [Reverse a string](#reverse-a-string)
|
||||||
@ -97,6 +97,15 @@ const anagrams = str => {
|
|||||||
// anagrams('abc') -> ['abc','acb','bac','bca','cab','cba']
|
// 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
|
### Array difference
|
||||||
|
|
||||||
Create a `Set` from `b`, then use `Array.filter()` on `a` to only keep values not contained in `b`.
|
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
|
```js
|
||||||
const remove = (arr, func) =>
|
const remove = (arr, func) =>
|
||||||
|
Array.isArray(arr) ?
|
||||||
arr.filter(func).reduce((acc, val) => {
|
arr.filter(func).reduce((acc, val) => {
|
||||||
arr.splice(arr.indexOf(val), 1)
|
arr.splice(arr.indexOf(val), 1)
|
||||||
return acc.concat(val);
|
return acc.concat(val);
|
||||||
}, [])
|
}, [])
|
||||||
|
: [];
|
||||||
//remove([1, 2, 3, 4], n => n % 2 == 0) -> [2, 4]
|
//remove([1, 2, 3, 4], n => n % 2 == 0) -> [2, 4]
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@ -3,6 +3,6 @@
|
|||||||
Use `Array.concat()` to concatenate and array with any additional arrays and/or values, specified in `args`.
|
Use `Array.concat()` to concatenate and 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], [1, 2, 3, [4]]) -> [1, 2, 3, [4]]
|
// ArrayConcat([1], [1, 2, 3, [4]]) -> [1, 2, 3, [4]]
|
||||||
```
|
```
|
||||||
|
|||||||
@ -4,9 +4,11 @@ Remove elements from `arr` that are returns truthy. Use `Array.filter()` to find
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
const remove = (arr, func) =>
|
const remove = (arr, func) =>
|
||||||
|
Array.isArray(arr) ?
|
||||||
arr.filter(func).reduce((acc, val) => {
|
arr.filter(func).reduce((acc, val) => {
|
||||||
arr.splice(arr.indexOf(val), 1)
|
arr.splice(arr.indexOf(val), 1)
|
||||||
return acc.concat(val);
|
return acc.concat(val);
|
||||||
}, [])
|
}, [])
|
||||||
|
: [];
|
||||||
//remove([1, 2, 3, 4], n => n % 2 == 0) -> [2, 4]
|
//remove([1, 2, 3, 4], n => n % 2 == 0) -> [2, 4]
|
||||||
```
|
```
|
||||||
|
|||||||
Reference in New Issue
Block a user