Ad
  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    This solution avoids using Array.filter() for two reasons:

    1. Array.filter() maintains and returns a separate copy of an array containing all filtered elements. This is heavy code and shouldn't be used when all we're doing is testing the elements of an array against the passed predicate.

    2. Array.filter() must examine all elements of the array and collect items that satisfy the passed predicate. Again, this is not optimal when we could simply terminate the loop once our predicate is false.