Created
September 16, 2018 17:34
-
-
Save tomhodgins/0eb5d42b300a097337ba89846797f93a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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