forked from Chalarangelo/30-seconds-of-code
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7b43ca8
commit e8293d8
Showing
3 changed files
with
18 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters