30 Days Of JavaScript

Day 11: Higher Order Functions Part 2

Lesson 2: some

some() isn't used all that often but it's useful to know about.

In natural language the description for some() would be "Tell me if some of my items match this condition"

Like find() it look at each item in your array and apply the function you give it, as soon as one element causes your function to return true some() will stop iterating over your array and return true. If it gets to the end of the array and none of the elements matched your condition, then it will return false.

Let's see if any of our cars have top speeds over 140 and then 250.

You can see the first log is true and the second is false. The trick here is that as soon as it found an element that met the condition some() returned true to give you a bit of an efficient boost, nothing major but it's something.


Go Pro?

If you upgraded to pro, sign in here

  • About
  • Blog
  • Privacy
Looking to email me? You can get me on my first name at allthecode.co