Glasgow Class 6 Melese Berehannu JavaScript-Core-1-Coursework-Week3 - #239
Glasgow Class 6 Melese Berehannu JavaScript-Core-1-Coursework-Week3#239Melesegithub wants to merge 2 commits into
Conversation
| const arrayOfString = []; | ||
| for (let city of cities) { | ||
| arrayOfString.push(`The temperature in ${city} is ${temperatureService(city)} degrees`) | ||
| } | ||
| return arrayOfString; |
There was a problem hiding this comment.
I like how you have simplified your code Melese. I found it easier to understand.
| const newArray = []; | ||
| for (let articleTitle of allArticleTitles){ | ||
| if (articleTitle.length <= 65){ | ||
| newArray.push(articleTitle) | ||
| } | ||
| } | ||
| return newArray; |
There was a problem hiding this comment.
Good! Although it's good to try and make variable names reflect what they are doing. For example here, a better name than newArray would have been, potentialHeadlines or similar
There was a problem hiding this comment.
This is another good function Melese. Easy for someone else to follow.
| }else{ | ||
| titleWithFewestWord = titleWithFewestWord; |
There was a problem hiding this comment.
I don't think we need this else statement here as it's not doing anything. titleWithFewestWord already equals titleWithFewestWord. We can just stick with the if statement only
| const headlinesWithNumber =[]; | ||
| for (let article of allArticleTitles){ | ||
| for (let char of article){ | ||
| if(char.match(/[0123456789]/g)){ | ||
| headlinesWithNumber.push(article);break; | ||
| } | ||
| } | ||
| }return headlinesWithNumber; | ||
|
|
| let averageNumberOfCharacter = 0; | ||
| for (let articleTitle of allArticleTitles){ | ||
| averageNumberOfCharacter = averageNumberOfCharacter + articleTitle.length | ||
| } | ||
| return Math.round((averageNumberOfCharacter/allArticleTitles.length).toFixed(0)) | ||
| } |
| const averagePrices = []; | ||
|
|
||
| for (let closingPriceForStock of closingPricesForAllStocks){ | ||
| averagePrices.push(Number(((closingPriceForStock.reduce((a,b) => a + b, 0))/(closingPriceForStock.length)).toFixed(2))) | ||
| } | ||
| return averagePrices; | ||
|
|
||
| } | ||
|
|
| const priceDescription = []; | ||
| for (let i = 0; i < closingPricesForAllStocks.length; i++){ | ||
| priceDescription.push(`The highest price of ${stocks[i].toUpperCase()} in the last 5 days was ${(((closingPricesForAllStocks[i]).sort(function(a,b){return a - b})[closingPricesForAllStocks[i].length-1]).toFixed(2))}`) } | ||
| return priceDescription; |
There was a problem hiding this comment.
This is great. The only suggestion I would make is to format your code so that it's easier to read. I think we are going to talk about this in class tomorrow :)
annacollins85
left a comment
There was a problem hiding this comment.
Great work! You've shown a lot of understanding of arrays here 🙌
js1 week 3