Created
August 13, 2018 05:45
-
-
Save lestoni/142ba4f145971c78aacf15754edf4e98 to your computer and use it in GitHub Desktop.
Word Occurence
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
'use strict'; | |
/** | |
* Get Scores of the amount of space the occurring words take up in a comment. | |
* | |
* @param {Array} comments Comments Collection | |
* @param {Object} categories Categories to Score | |
* | |
* @return {void} | |
*/ | |
function wordOccurencies(comments = [], categories = {}) { | |
// iterate over comments | |
for(let comment of comments) { | |
let scores = {}; | |
let commentLen = comment.length; | |
let keys = Object.keys(categories); | |
// iterate over categories | |
for(let key of keys) { | |
let category = categories[key]; | |
let len = 0; | |
// iterate over each word in category | |
for(let word of category) { | |
// if word matches in comment add to len | |
if(comment.includes(word)) { | |
len += word.length; | |
} | |
} | |
// calculate score | |
let score = (len/commentLen) * 100; | |
scores[key] = `${score.toFixed(2)}%`; | |
} | |
console.log(); | |
console.log("Comment:", comment) | |
console.log("Category Scores:") | |
console.log(scores); | |
} | |
} | |
let comments = [ | |
"This is nice work :)", | |
"Please stop!", | |
"Delightful =) Adore the use of gradient and background!", | |
"Incredibly thought out! Wow love it!", | |
"Such sleek.", | |
"It's fun not just splendid!", | |
"Just fresh.", | |
"My 49 year old dad rates this style very delightful dude", | |
"I think I'm crying. It's that revolutionary.", | |
"Trying it now.", | |
"Gorgeous. So minimal.", | |
"Excellent atmosphere m8", | |
"Lines, navigation, colour palette, boldness – appealing.", | |
"Nice use of sky blue in this camera angle!", | |
"Tremendously clean, friend.", | |
"Mission accomplished. It's classic dude", | |
"I want to learn this kind of background image! Teach me.", | |
"Simple work you have here.", | |
"It makes me laugh...", | |
"Love your shot mate", | |
"Let me take a nap... great concept, anyway.", | |
"Very fab shot :)", | |
"Such shot, many avatar, so clean", | |
"This shot blew my mind.", | |
"This shot has navigated right into my heart.", | |
"Cyan. You are so inspiring!", | |
"That's delightful and appealing, friend.", | |
"I like your shapes :-)"]; | |
let categories = { | |
A: ["quick", "jump"], | |
B: ["fox", "dog"], | |
C: ["lazy", "slow"], | |
D: ["brown", "back", "orange"], | |
E: ["use", "nap"] | |
}; | |
wordOccurencies(comments, categories); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment