Sanjana's Implementation of Identifying the Most Common Word in a Paragraph#5
Sanjana's Implementation of Identifying the Most Common Word in a Paragraph#5sanja-jonna wants to merge 5 commits intomainfrom
Conversation
|
|
||
| var bannedArray = []; | ||
| bannedArray.push(banned); | ||
| wordsInPargrphArr = wordsInPargrphArr.filter(word => word != banned); |
There was a problem hiding this comment.
Always use !== instead of != (and same for ===) in Javascript, unless you're specifically looking to coerce values. I know the udemy course has more info somewhere in the first half
|
|
||
| getDictWithFrequencies(paragraphArr, bannedWordsArr) { | ||
| var frequencyDict = new Object(); | ||
| if(key in frequencyDict) { |
There was a problem hiding this comment.
I'd add a space between 'if' and first (
Same for 'for' loops (line 21 looks good)
There was a problem hiding this comment.
Also, haven't seen (propertyName in objectName) used before--that's cool. Most of the time I tend to see objectName.hasOwnProperty(propName), which makes sure that the property is not on the object's prototype
| getDictWithFrequencies(paragraphArr, bannedWordsArr) { | ||
| var frequencyDict = new Object(); | ||
| if(key in frequencyDict) { | ||
| value = frequencyDict[key]; |
There was a problem hiding this comment.
I'm pretty sure you should have declare 'value' with var or let here, unlike Object.entries which provides [key, value].
Without a var, it becomes an implicit global level variable
There was a problem hiding this comment.
pretty sure just in case I'm missing something like Object.entries
| var wordsOfHighFrequency = [] | ||
|
|
||
| for(const [key, value] of Object.entries(frequencyDict)) { | ||
| if(value == max) { |
danego
left a comment
There was a problem hiding this comment.
Nice Javascript code--it looks good! I thought you named your variables and functions well and the overall look matched what I have in mind for JS.
Three quick notes:
- One thing you could change would be adding more functions. For example, you could add a very simple function to prepare the paragraph (~lines 61) or adding function calls w/in getWordsWithHighestFreq(). Tbh, I tend to code more like your code here and don't like to abstract away too much, but Sirrele is always pushing for more functions (and single purpose ones). Robert's branch had a lot of well-designated functions, for reference
- The task.md said the answer would be unique, so no need to make wordsOfHighFrequency an array, but good job nonetheless.
- I like the node bonus stuff you added!
No description provided.