Skip to content

Commit

Permalink
Tag, lint, build
Browse files Browse the repository at this point in the history
  • Loading branch information
Chalarangelo committed Dec 15, 2017
1 parent 7b43ca8 commit e8293d8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
### Array
* [Array concatenation](#array-concatenation)
* [Array difference](#array-difference)
* [Array includes](#array-includes)
* [Array intersection](#array-intersection)
* [Array sample](#array-sample)
* [Array union](#array-union)
Expand Down Expand Up @@ -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)

### 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

Create a `Set` from `b`, then use `Array.filter()` on `a` to only keep values contained in `b`.
Expand Down
6 changes: 3 additions & 3 deletions snippets/array-includes.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
### 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
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
```
```
1 change: 1 addition & 0 deletions tag_database
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
anagrams-of-string-(with-duplicates):string
array-concatenation:array
array-difference:array
array-includes:array
array-intersection:array
array-sample:array
array-union:array
Expand Down

0 comments on commit e8293d8

Please sign in to comment.