Tag, lint, build
This commit is contained in:
14
README.md
14
README.md
@ -12,6 +12,7 @@
|
|||||||
### Array
|
### Array
|
||||||
* [Array concatenation](#array-concatenation)
|
* [Array concatenation](#array-concatenation)
|
||||||
* [Array difference](#array-difference)
|
* [Array difference](#array-difference)
|
||||||
|
* [Array includes](#array-includes)
|
||||||
* [Array intersection](#array-intersection)
|
* [Array intersection](#array-intersection)
|
||||||
* [Array sample](#array-sample)
|
* [Array sample](#array-sample)
|
||||||
* [Array union](#array-union)
|
* [Array union](#array-union)
|
||||||
@ -142,6 +143,19 @@ const difference = (a, b) => { const s = new Set(b); return a.filter(x => !s.has
|
|||||||
|
|
||||||
[⬆ back to top](#table-of-contents)
|
[⬆ back to top](#table-of-contents)
|
||||||
|
|
||||||
|
### Array includes
|
||||||
|
|
||||||
|
Use `slice()` to offset the array/string and `indexOf()` to check if the value is included.
|
||||||
|
Omit the last argument, `fromIndex`, to check the whole array/string.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const includes = (collection, val, fromIndex=0) => collection.slice(fromIndex).indexOf(val) != -1;
|
||||||
|
// includes("30-seconds-of-code", "code") -> true
|
||||||
|
// includes([1, 2, 3, 4], [1, 2], 1) -> false
|
||||||
|
```
|
||||||
|
|
||||||
|
[⬆ back to top](#table-of-contents)
|
||||||
|
|
||||||
### Array intersection
|
### Array intersection
|
||||||
|
|
||||||
Create a `Set` from `b`, then use `Array.filter()` on `a` to only keep values contained in `b`.
|
Create a `Set` from `b`, then use `Array.filter()` on `a` to only keep values contained in `b`.
|
||||||
|
|||||||
@ -1,10 +1,10 @@
|
|||||||
### Array includes
|
### Array includes
|
||||||
|
|
||||||
Use `slice()` to offset the array/string. `Array.indexOf()` returns `-1` if the sub-string/array dosen't contain the given `value`.
|
Use `slice()` to offset the array/string and `indexOf()` to check if the value is included.
|
||||||
|
Omit the last argument, `fromIndex`, to check the whole array/string.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const includes = (collection, val, fromIndex=0) => collection.slice(fromIndex).indexOf(val) != -1;
|
const includes = (collection, val, fromIndex=0) => collection.slice(fromIndex).indexOf(val) != -1;
|
||||||
|
|
||||||
// includes("30-seconds-of-code", "code") -> true
|
// includes("30-seconds-of-code", "code") -> true
|
||||||
// includes([1, 2, 3, 4], [1, 2], 1) -> false
|
// includes([1, 2, 3, 4], [1, 2], 1) -> false
|
||||||
```
|
```
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
anagrams-of-string-(with-duplicates):string
|
anagrams-of-string-(with-duplicates):string
|
||||||
array-concatenation:array
|
array-concatenation:array
|
||||||
array-difference:array
|
array-difference:array
|
||||||
|
array-includes:array
|
||||||
array-intersection:array
|
array-intersection:array
|
||||||
array-sample:array
|
array-sample:array
|
||||||
array-union:array
|
array-union:array
|
||||||
|
|||||||
Reference in New Issue
Block a user