Skip to content

Instantly share code, notes, and snippets.

@NyaGarcia
Last active October 10, 2019 20:00
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 NyaGarcia/157254f4d9be381134bf62698c0a2df0 to your computer and use it in GitHub Desktop.
Save NyaGarcia/157254f4d9be381134bf62698c0a2df0 to your computer and use it in GitHub Desktop.
Substituting a for loop with Array.map and Array.filter
function getNews(type) {
const allNews = getNewsFromWeb();
return getNewsContent(allNews, type);
}
function getNewsContent(newsList, type) {
return newsList
.filter(newsItem => newsItem.type === type)
.map(newsItem => newsItem.content);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment