learning-zone / javascript-basics

JavaScript Basics
https://learning-zone.github.io/javascript-basics/
1.75k stars 616 forks source link

Update filterArrayBasedOnAnotherArray.js #1

Closed tasawar-hussain closed 3 years ago

tasawar-hussain commented 3 years ago

Add alternate solution using filter, which is more readable and intended for filtering

learning-zone commented 3 years ago

Filter() and Reduce() both have their own advantages. filter() creates a new array by removing elements that don't belong. reduce(), on the other hand, takes all of the elements in an array and reduces them into a single value.