Skip to content

Instantly share code, notes, and snippets.

@iandesj
Last active November 14, 2019 13:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iandesj/9437862dbc7124342a514fd6b7cb0ca7 to your computer and use it in GitHub Desktop.
Save iandesj/9437862dbc7124342a514fd6b7cb0ca7 to your computer and use it in GitHub Desktop.
Examples of filter() vs for loop
const fruits = [ 'pineapple', 'apple', 'banana', 'pear' ];
const matchedFruits = fruits.filter((element) => {
return element.includes('apple');
});
let matchedFruitsAgain = [];
for (let i = 0; i < fruits.length; i++) {
if (fruits[i].includes('apple')) {
matchedFruitsAgain.push(fruits[i]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment