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

North-West-5/Shimen-Afshar/JavaScript-Core-1-Coursework-Week3 - #145

Open
ShimenAfshar wants to merge 3 commits into
CodeYourFuture:mainfrom
ShimenAfshar:main
Open

North-West-5/Shimen-Afshar/JavaScript-Core-1-Coursework-Week3#145
ShimenAfshar wants to merge 3 commits into
CodeYourFuture:mainfrom
ShimenAfshar:main

Conversation

@ShimenAfshar

Copy link
Copy Markdown

No description provided.

@Ekremteke Ekremteke 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 Shima these are so impressive. I could not find anything to add and to look your PR was instructive for me.

// TODO
let report=[]
for(let i = 0; i < cities.length; i++){
report[i]=`The temperature in ${cities[i]} is ${temperatureService(cities[i])} degrees`;

@Nomes27 Nomes27 Oct 2, 2022

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nice use of template literals! here you can use push, for example report.push(The temperature in ${cities[i]} is ${temperatureService(cities[i])} degrees)

do{
counter=generateRandomNumber();
}
while(counter<50);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nice do-while loop implementation :) remember to use <= here rather than just < as the returned number needs to be greater than 50

function potentialHeadlines(allArticleTitles) {
// TODO
if(allArticleTitles.lengh !== 0){
allArticleTitles = ARTICLE_TITLES.filter((el) => el.length <= 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.

here you are using a mixture of allArticleTitles which is passed into the function and ARTICLE_TITLES (just use allArticlesTitles). Good use of the filter array method, but you don't need the if statement, for example if you do let shortTitles = allArticleTitles.filter((el) => el.length <= 65) and then return this, it will return an empty array if allArticleTitles.length is 0 :)

function titleWithFewestWords(allArticleTitles) {
// TODO
let arr = allArticleTitles;
let newArr = arr.sort((a, b) => a.length - b.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.

good use of sort here, to sort an array without mutating the original array you can use the spread operator: let newArr = [...allArticleTitles].sort((a, b) => a.length - b.length);. We could use a different array name here to make the code more readable, for example changing newArr to something like fewestWordsArr

}
}
return arr;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

regex is really useful for functions like this - this is a good site to learn more & have a play around https://regex101.com/
for the above you can do something like (/\d/.test(stringYouWantToTest)) the \d checks for any digit, returning true if a digit is found

for (let articleTitle of allArticleTitles) {
total += articleTitle.length;
}
average = total / 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.

really nice solution well done, you could just define average on line 63, for example let average = total / allArticleTitles.length; and get rid of your definition on line 59 (as it's not really doing anything at the moment)

Comment thread 2-mandatory/4-stocks.js
Comment on lines +40 to +41
for (let i = 0; i < CLOSING_PRICES_LAST_5_DAYS_FOR_ALL_STOCKS.length; i++) {
for (let j = 0; j < CLOSING_PRICES_LAST_5_DAYS_FOR_ALL_STOCKS[i].length; j++) {

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 solution, well done on using multiple loops!

Comment thread 2-mandatory/4-stocks.js
"The highest price of " + stocks[i].toUpperCase() + " " + "in the last 5 days was " + highestNum.toFixed(2));

}
return highestPrice;

@Nomes27 Nomes27 Oct 2, 2022

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nice solution :) The Math.max method is useful for finding the highest number, you can pass in an array like so:
let highestNum = Math.max(...closingPricesForAllStocks[i])

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