Skip to content

Commit 3d5ff82

Browse files
tomhooijengathooijenga
and
thooijenga
authored
Add includes method #15 (#20)
* Add `includes` method. * linting Co-authored-by: thooijenga <[email protected]>
1 parent 487a65c commit 3d5ff82

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ iterator.new(iterable)
2323
.find(...)
2424
.findIndex(...)
2525
.some(...)
26+
.includes(...)
2627
.intoArray()
2728
.intoSet()
2829
.intoMap()

lib/main.js

+17-2
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export const Iterator = {
8787
},
8888

8989
/**
90-
* Applies the lambda function to each item of the interable.
90+
* Applies the lambda function to each item of the iterable.
9191
*
9292
* @param {ForEachCallback} lambda
9393
*/
@@ -197,7 +197,22 @@ export const Iterator = {
197197
},
198198

199199
/**
200-
* Flattens a nested interable structure for n depth.
200+
* Determine if the given value is included in the iterable.
201+
* Optionally specify a position at which to begin searching.
202+
*
203+
* @param {*} value
204+
* @param {number} [fromIndex=0]
205+
*
206+
* @return {boolean}
207+
*/
208+
includes(value, fromIndex = 0) {
209+
return !!this.find((item, index) => {
210+
return item === value && index >= fromIndex;
211+
});
212+
},
213+
214+
/**
215+
* Flattens a nested iterable structure for n depth.
201216
*
202217
* @param {number} [depth=1]
203218
*

0 commit comments

Comments
 (0)