London_10-Saliha_Popal-JavaScript-Core-1-Coursework-Week3 - #231
London_10-Saliha_Popal-JavaScript-Core-1-Coursework-Week3#231SalihaPopal wants to merge 3 commits into
Conversation
| statement.push(`The temperature in ${city} is ${temperature} degrees`) | ||
| } | ||
| return statement; | ||
| } |
There was a problem hiding this comment.
Comment: Well done!
Consider: You could also iterate [i]
function getTemperatureReport(cities) {
const temperatureReport = [];
for(let i = 0; i < cities.length; i++) {
const temperature = temperatureService(cities[i]);
temperatureReport.push(The temperature in ${cities[i]} is ${temperature} degrees);
}
return temperatureReport;
| } | ||
|
|
||
| return fewestWords; | ||
| } |
| } | ||
|
|
||
| return headlinesWithNumbers; | ||
| } |
There was a problem hiding this comment.
Comment: Interesting. I see you used .charAt and NaN. I have not seen any other use it.
My solution:
let newArr = [];
for (let title of allArticleTitles) {
if (/[0-9]/.test(title) === true) {
newArr.push(title);
}
}
return newArr;
}
| const averageChars = Math.round(totalChars / allArticleTitles.length); | ||
|
|
||
| return averageChars; | ||
| } |
There was a problem hiding this comment.
Comment: I see you use just 1 global variable (let). Mine has 2. Well done
| } | ||
|
|
||
| return priceChanges; | ||
| } |
There was a problem hiding this comment.
Comment: Nice solution
Here is one with less code:
function getPriceChanges(closingPricesForAllStocks) {
// TODO
let changedPrices = [];
for (let arrayWithPrices of closingPricesForAllStocks) {
let changedPrice = arrayWithPrices[arrayWithPrices.length - 1] - arrayWithPrices[0];
changedPrices.push(Number(changedPrice.toFixed(2)));
}
return changedPrices;
}
| } | ||
|
|
||
| return descriptions; | ||
| } |
There was a problem hiding this comment.
Comment: Math.max was a clever solution. New one for me
| // TODO | ||
| } | ||
|
|
||
| function getTemperatureReport(cities){ |
There was a problem hiding this comment.
This looks good 👍
One small suggestion - keep an eye on indentation, as it will make it easier for other developers to read your code.
| } | ||
|
|
||
| function getTemperatureReport(cities){ | ||
| const statement = []; |
There was a problem hiding this comment.
Another small point - is statement a good name for this variable? Maybe statements or weatherReports would be a better name as this is an array which contains many statements 😄
| // TODO | ||
| } | ||
|
|
||
| function potentialHeadlines(allArticleTitles) { |
There was a problem hiding this comment.
Looks perfect!
As an extra exercise - could you re-write this using the filter array method?
| (you can assume words will always be seperated by a space) | ||
| (you can assume words will always be separated by a space) | ||
| */ | ||
| function titleWithFewestWords(allArticleTitles) { |
There was a problem hiding this comment.
It looks like this solution will give you the title with the fewest characters, but this might not be the fewest words.
With a couple of small changes you could fix this 😄
| Implement the function below to return this number - rounded to the nearest integer. | ||
| */ | ||
|
|
||
| function averageNumberOfCharacters(allArticleTitles) { |
| @@ -34,8 +34,24 @@ const CLOSING_PRICES_LAST_5_DAYS_FOR_ALL_STOCKS = [ | |||
| Functions can help with this! | |||
| */ | |||
| function getAveragePrices(closingPricesForAllStocks) { | |||
There was a problem hiding this comment.
Good job on this one 👍
| The stock ticker should be capitalized. | ||
| The price should be shown with exactly 2 decimal places. | ||
| */ | ||
| function highestPriceDescriptions(closingPricesForAllStocks, stocks) { |
There was a problem hiding this comment.
Nice use of Math.max here!
| // `getStations` goes here | ||
|
|
||
|
|
||
| function getStations() { |
There was a problem hiding this comment.
This looks perfect!
For practice, you could try re-writing this with the filter array method.
|
Great job on this coursework! Well done. |
|
|
||
| // Using the filter function without loops | ||
|
|
||
|
|
There was a problem hiding this comment.
This looks perfect, well done 😄
No description provided.