Glasgow 6 - Malkit Benning - JS Core 1 Week 3 - #225
Conversation
weather and financial times exercises complete
completed all mandatory exercises
all tests passed
Dedekind561
left a comment
There was a problem hiding this comment.
Well done, Malkit!
Some excellent work here - generally really good variable names, which make your code really clear to read.
I've left a few minor comments for things to improve too!
| */ | ||
| function potentialHeadlines(allArticleTitles) { | ||
| // TODO | ||
| const charLimit = 65; |
There was a problem hiding this comment.
Excellent - great use of a variable name charLimit! No magical numbers :)
| function potentialHeadlines(allArticleTitles) { | ||
| // TODO | ||
| const charLimit = 65; | ||
| const articlesUnderLimit = []; |
| // TODO | ||
| // TODO | ||
| let charCount = 0; | ||
| const articleTitleCount = allArticleTitles.length; |
There was a problem hiding this comment.
Don't generally need to store allArticlesTitles.length in a variable. Absolutely fine to write allArticleTitles.length inline.
| // TODO | ||
| let charCount = 0; | ||
| const articleTitleCount = allArticleTitles.length; | ||
| for (const articleTitle of allArticleTitles) { |
There was a problem hiding this comment.
| for (const articleTitle of allArticleTitles) { | |
| for (const articleTitle of allArticleTitles.length) { |
| for (const companyPrices of closingPricesForAllStocks) { | ||
| const daysCount = companyPrices.length; | ||
| let companyPriceTotal = 0; | ||
| for (const singlePrice of companyPrices) { |
There was a problem hiding this comment.
This is a good solution - variable names are very clear.
As a refactor, consider moving the inner logic in the for loop into a separate function. What name would you give to this function?
| for (const companyPrices of closingPricesForAllStocks) { | ||
| const firstPricePosition = 0; | ||
| const lastPricePosition = companyPrices.length - 1; | ||
| const stockPriceDiff = |
| function findFirstJulyBDay(birthdays) { | ||
| // TODO | ||
| // TODO | ||
| // for (let i = 0; i < BIRTHDAYS.length; i++) { |
There was a problem hiding this comment.
Remember to remove old comments. Remember you still have old versions of your code in your version history - so you should be able to inspect the old version if you want to.
AppolinFotso
left a comment
There was a problem hiding this comment.
Well done @malkitbenning! Your codes are clean and readable.
msimmdev
left a comment
There was a problem hiding this comment.
Hi Mal, great work on this exercise.
There's a few problems in the extra exercises I've noted, but these will be things we're exploring more in upcoming classes.
I noticed that a lot of the files have been reformatted, I'd suggest checking your editor settings as where possible it's better to avoid reformatting existing code in a file.
|
|
||
| We have a list of cities that the user wants to track. | ||
| We also already have a temperatureService function which will take a city as a parameter and return a temparature. | ||
| We also already have a temperatureService function which will take a city as a parameter and return a temperature. |
| const charLimit = 65; | ||
| const articlesUnderLimit = []; | ||
|
|
||
| for (const articleTitle of allArticleTitles) { |
There was a problem hiding this comment.
Suggestion: What you've done is fine, but it would also be appropriate to use a filter here such as
articlesUnderLimit = allArticleTitles.filter((articleTitle) => articleTitle <= charLimit);| */ | ||
| function titleWithFewestWords(allArticleTitles) { | ||
| // TODO | ||
| // TODO |
There was a problem hiding this comment.
Nitpick: Remove the TODO comments once you've done the work, in production code TODO comments are often used to note places where further work still needs to be done so leaving it in can cause confusion
| let shortestTitle = ""; | ||
| let shortestSpaceCount = 0; | ||
| for (const title of allArticleTitles) { | ||
| if (shortestTitle === "") { |
There was a problem hiding this comment.
Question: Why do we need to have a check for blank strings specifically?
| */ | ||
|
|
||
| function containsNumbers(str) { | ||
| return /[0-9]/.test(str); |
There was a problem hiding this comment.
Suggestion: This works and is OK, however in the scope of work in this course I'd recommend avoiding regex's. Instead this could be done by using the string includes function.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes
| (Hint: remember that you can also loop through the characters of a string if you need to) | ||
| */ | ||
|
|
||
| function containsNumbers(str) { |
There was a problem hiding this comment.
Praise: Good separation of logic into a new function
| const daysCount = companyPrices.length; | ||
| let companyPriceTotal = 0; | ||
| for (const singlePrice of companyPrices) { | ||
| companyPriceTotal += singlePrice; |
There was a problem hiding this comment.
Suggestion: As we discussed in our recent meetings, it can be better to deal with currency values as pennies when doing math operations on them, here it might make sense to do
companyPriceTotal += singlePrice * 100;that way we can aggregate a total number of pennies and avoid a lot of floating point math. Remember you will need to divide by 100 at the end.
| */ | ||
| let highestBooks = []; | ||
| let highBook = {}; | ||
| let finalList = []; |
There was a problem hiding this comment.
Issue: While you can declare variables like this in the body of a script it's generally bad practice for this type of script. (We call these globals) Instead you should try and declare your variables in the function body and if you need to share variables between functions pass them around in parameters.
|
|
||
| function getHighestRatedInEachGenre(books) { |
There was a problem hiding this comment.
Suggestion: After next class have a think about how this solution might be simplified by using an object.
|
|
||
| function generateFibonacciSequence(n) { | ||
| // TODO | ||
| // TODO |
All exercises completed and all tests passed.