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

Glasgow Class 6 - Mandy Cheung - JS1 - Week 3 - #254

Open
m4ndycheung wants to merge 12 commits into
CodeYourFuture:mainfrom
m4ndycheung:main
Open

Glasgow Class 6 - Mandy Cheung - JS1 - Week 3#254
m4ndycheung wants to merge 12 commits into
CodeYourFuture:mainfrom
m4ndycheung:main

Conversation

@m4ndycheung

Copy link
Copy Markdown

No description provided.

@hussein-alsayed

Copy link
Copy Markdown

great, I like how you're committed to the habit of committing :D
good naming as well. I always struggle to describe my commits xD

@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.

Well done on completing all the exercises, this is generally to a good standard and your solutions are appropriate.

I noticed a few instances where you're using a for loop with an iterator variable but not declaring your iterator with let or const. This will work, but is bad practice you should make sure to declare all your variables.

I also notices a few instances of using a for loop where a for...of loop would be better, this isn't a big problem, but using for...of for simple iterations makes your code easier to understand and reduces the amount of code you need to write.

}
let temperatureReportResults = [ ];

for (i = 0; i < cities.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.

Suggestion: Use a for (city of cities) loop here. This reduces the amount of code you need to write and it is easier for a reader to understand your intention.


let smallestTitle = allArticleTitles[0];

for (i = 1; i < allArticleTitles.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.

Issue: The iterator variable i in a for loop should be declared with let. For example

for (let i = 1; i < allArtivlesTitles.length; i++)

Suggestion: Use a for...of loop instead of a for loop to improve readability

let headlinesWithNumbers = [ ];
const numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];

for (i = 0; i < allArticleTitles.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.

Issue: The iterator variable i in a for loop should be declared with let.
Suggestion: Use a for...of loop instead of a for loop to improve readability

let totalCharactersPerTitle = [ ];

// To count the characters per title and add them to totalCharactersPerTitle
for (i = 0; i < allArticleTitles.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.

Issue: The iterator variable i in a for loop should be declared with let.
Suggestion: Use a for...of loop instead of a for loop to improve readability


// To store the sum of total characters
let totalCharacters = 0;
totalCharactersPerTitle.forEach( item => {

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 implementation is fine, but this could also be done with a reducer. e.g.

let totalCharaters = totalCharactersPerTitle.reduce((iterator, element) => iterator + element);

Comment thread 2-mandatory/3-stocks.js

let changeInPrice = [ ];

for (i = 0; i < array.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.

Issue: The iterator variable i in a for loop should be declared with let.
Suggestion: Use a for...of loop instead of a for loop to improve readability

Comment thread 2-mandatory/3-stocks.js
// This loop cycles through each stock, the i is the 5 day stock for AAPL, MSFT etc.
for (i = 0; i < closingPricesForAllStocks.length; i++) {
let totalStock = 0;
closingPricesForAllStocks[i].forEach((element) => {

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: Instead of doing * 100 on the calculated average at the end of the function do a * 100 on each element when adding it to totalStock. This lets you do more of the math with integers which reduces the floating point inaccuracies caused by math with floating point numbers.

Comment thread 2-mandatory/3-stocks.js
let fifthDayPrice = closingPricesArray[i][lengthOfInnerArray - 1];
let firstDayPrice = closingPricesArray[i][0];

let fifthDayMinusFirstDayRounded = Math.round((fifthDayPrice - firstDayPrice) * 100) / 100;

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 do * 100 on fifthDayPrice and firstDayPrice separately so the - operation will occur on integers instead of floating point numbers, reducing floating point math inaccuracy.

let hello = sayHello();
console.log(hello);

// the function won't return anything, so the variable hello will return undefined.

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: the variable hello will be undefined, try to avoid using the word return for variables and just use it for functions.


// TODO - Write for loop code here

for (i = 0; i < WRITERS.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.

Issue: The iterator variable i in a for loop should be declared with let.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants