Skip to content
This repository was archived by the owner on Jan 14, 2024. It is now read-only.

Glasgow 6 - Malkit Benning - JS Core 1 Week 3 - #225

Open
malkitbenning wants to merge 4 commits into
CodeYourFuture:mainfrom
malkitbenning:main
Open

Glasgow 6 - Malkit Benning - JS Core 1 Week 3#225
malkitbenning wants to merge 4 commits into
CodeYourFuture:mainfrom
malkitbenning:main

Conversation

@malkitbenning

Copy link
Copy Markdown

All exercises completed and all tests passed.

weather and financial times exercises complete
completed all mandatory exercises
all tests passed

@Dedekind561 Dedekind561 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent - great use of a variable name charLimit! No magical numbers :)

function potentialHeadlines(allArticleTitles) {
// TODO
const charLimit = 65;
const articlesUnderLimit = [];

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good variable name

// TODO
// TODO
let charCount = 0;
const articleTitleCount = allArticleTitles.length;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for (const articleTitle of allArticleTitles) {
for (const articleTitle of allArticleTitles.length) {

Comment thread 2-mandatory/3-stocks.js
for (const companyPrices of closingPricesForAllStocks) {
const daysCount = companyPrices.length;
let companyPriceTotal = 0;
for (const singlePrice of companyPrices) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Comment thread 2-mandatory/3-stocks.js
for (const companyPrices of closingPricesForAllStocks) {
const firstPricePosition = 0;
const lastPricePosition = companyPrices.length - 1;
const stockPriceDiff =

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very readable 👍

function findFirstJulyBDay(birthdays) {
// TODO
// TODO
// for (let i = 0; i < BIRTHDAYS.length; i++) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@Dedekind561 Dedekind561 added reviewed A mentor has reviewed this code and removed review in progress labels Mar 8, 2023

@AppolinFotso AppolinFotso left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well done @malkitbenning! Your codes are clean and readable.

@msimmdev msimmdev left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Praise: Good Spot

const charLimit = 65;
const articlesUnderLimit = [];

for (const articleTitle of allArticleTitles) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 === "") {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: Why do we need to have a check for blank strings specifically?

*/

function containsNumbers(str) {
return /[0-9]/.test(str);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Praise: Good separation of logic into a new function

Comment thread 2-mandatory/3-stocks.js
const daysCount = companyPrices.length;
let companyPriceTotal = 0;
for (const singlePrice of companyPrices) {
companyPriceTotal += singlePrice;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 = [];

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines 24 to +25

function getHighestRatedInEachGenre(books) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: After next class have a think about how this solution might be simplified by using an object.

Comment thread 3-extra/3-fibonacci.js

function generateFibonacciSequence(n) {
// TODO
// TODO

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: Remove TODO comments

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

reviewed A mentor has reviewed this code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants