some, every, find, and findindex

Introduction
In this subunit, we'll explore some array methods with more specialized applications: some, every, find, and findindex. Unlike the methods in the last unit, you won't be using them all the time, but they are still essential for you to know. You will often use them in conjunction with the methods introduced in the last subunit. Again, these might not be the most conceptually intuitive methods, but stick with it, and you'll gain the tools you need to succeed in the professional world.
some/every
Goals
Understand what some and every do
Write your own version of some and every
some
Iterates through an array
Runs a callback on each value in the array
If the callback returns true for at least one single value, return true
Otherwise, return false
the result of the callback will always be a boolean
An Example
How Does It Work
Iterates through an array
Runs a callback on each value in the array
If the callback returns true for at least one single value, return true
Otherwise, return false
Using Some In A Function
When You Would Use Some
You need to determine if at least one value in an array exists, and you have to determine this by using a callback ( not includes/indexOf)
A simple alternative to using filter and seeing if the array contains at least one element
every
Iterates through an array
Runs a callback on each value in the array
If the callback returns false for any single value, return false
Otherwise, return true
the result of the callback will always be a boolean
An Example
How Does It Work
Iterates through an array
Runs a callback on each value in the array
If the callback returns false for any single value, return false
Otherwise, return true
Using Every In A Function
When You Would Use Every
You need to determine if every value in an array exists, and you have to determine this by using a callback
A simple alternative to using filter and seeing if the filtered array is of the same length as the original array
find/findIndex
Goals
Understand what find and findIndex do
Write your own version of find and findIndex
find
Iterates through an array
Runs a callback on each value in the array
If the callback returns true at any point, return the value in the array that we're iterating over
Otherwise, return undefined
An Example
How Does It Work
Iterates through an array
Runs a callback on each value in the array
If the callback returns true at any point, return the value we're iterating over
Otherwise, return undefined
Using Find in a Function
When You Would Use Find
You need to determine if a value in an array exists, and you have to determine this by using a callback
A simple alternative to using filter and accessing the first element of the filtered array
findIndex
Iterates through an array
Runs a callback on each value in the array
If the callback returns true for any single value, return the index at which that value is found
Otherwise, return -1
An Example
How Does It Work
Iterates through an array
Runs a callback on each value in the array
If the callback returns true for any single value, return the index at which that value is found
Otherwise, return -1
Using findIndex In A Function
When You Would Use findindex
You need to determine the index of a value in an array if it exists, and you have to determine this by using a callback
A better version of indexOf to be used when a callback is necessary