Skip to content

Instantly share code, notes, and snippets.

@tomhodgins
Created September 16, 2018 17:34
Show Gist options
  • Save tomhodgins/0eb5d42b300a097337ba89846797f93a to your computer and use it in GitHub Desktop.
Save tomhodgins/0eb5d42b300a097337ba89846797f93a to your computer and use it in GitHub Desktop.
const articles = [
{
title: 'How to make an example',
body: 'This tutorials shows you how to make a nice example. First Write some text!'
},
{
title: 'My super frustrating personal blog entry',
body: 'Im feeling so happy and angry and sad and glad and hungry and tired.'
}
]
function analyze(articles) {
return articles.map(article =>
article = {
...article,
score: {
tutorial: ['how', 'tutorial']
.some(word => article.body.toLowerCase().includes(word))
? 1
: 0,
personal: ['happy', 'feeling']
.some(word => article.body.toLowerCase().includes(word))
? 1
: 0
}
}
)
}
function categorize(articles) {
return {
tutorials: articles.filter(
article => article.score.tutorial === 1 && article.score.personal === 0
),
blogs: articles.filter(
article => article.score.personal
)
}
}
console.log(
categorize(analyze(articles))
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment