Write Your Own Includes
Write the code, see it run, pass the checks.
The problem
- easy
- Code
Write myIncludes(items, value, fromIndex) without using the built-in includes, indexOf or lastIndexOf. Return true if any item from position fromIndex onwards matches value, and false otherwise. Compare the way includes does: NaN matches NaN, 0 and minus 0 match each other, and everything else uses triple equals. fromIndex defaults to 0. A negative fromIndex counts back from the end, so minus 2 searches only the last two items, and one further back than the start searches the whole array. A fromIndex at or past the end finds nothing.
Your code must pass
- Finds a value with triple equals
- Finds NaN, and treats 0 and minus 0 as equal
- Starts the search at fromIndex
- Counts a negative fromIndex back from the end
- Works without the built-in includes or indexOf