This video discusses every and some, two Lodash functions used to tell if any or all of the elements in an array fit a piece of criteria. We show how instead of using a for loop to cycle through an array, we can use every and some, leading to cleaner, more robust code.
- [Narrator] We now move onto two functions that behave…very similarly to each other.…These functions are called some and every.…Some and every are similar to filter but instead of…giving us an array's output, they simply return…true or false, some returns true if the function…we give it returns true for at least one of the elements…in the array, every returns true only if…the function we give it returns true for all…of the elements in the array and false otherwise.…So for example, if we have an array of all even numbers…and we pass that into every along with a function…that checks if each element is even, every would…return true because all of the elements are even.…
If we pass this array into some with the same criteria,…it will return true also because at…least one of the elements is even.…If we change one of the elements in our array…so that it's odd and then pass it into every,…every now returns false since all of the elements…are not even, however if we pass this same array into some,…it still returns true since at least…
- What's functional programming?
- Functional vs. object-oriented programming
- First-class functions
- Higher-order functions
- Array functions
- Mapping, filtering, and reducing
- Simple callbacks
- Callbacks with arguments