WM4 - Kerim Zamir - JS Core 1 - Week 3 - #78
Conversation
*note* for doesnt work
*note* const is not needed before i in for of loop
*note* const average = (closingPricesForAllStocks.map((array) => array.reduce((r, current) => r + current / array.length, 0))).map((element) => parseFloat(element.toFixed(2))); Should be used more often
SaadiaELF
left a comment
There was a problem hiding this comment.
Good work 👏
I have just remarked that you are using a capital first letter in variables name, I'm not sure if it's the right naming convention for JS. And also variable name should be meaningful
| function evenNumbers(n) | ||
| { | ||
| let total = "0"; | ||
| let calc = 0; | ||
|
|
||
| if (n === 0) | ||
| { | ||
| return console.log(""); | ||
| } | ||
|
|
||
| for(let i = 1; i < n; i++) | ||
| { | ||
| calc = calc + 2; | ||
|
|
||
| total = total + ", " + calc; | ||
| } | ||
|
|
||
| return console.log(total); |
There was a problem hiding this comment.
The instructions said that you should use a while loop.
Consider using an array to store the values and then convert it to string using 'toString' method
|
|
||
| for (let i = 0; i < WRITERS.length; i++) | ||
| { | ||
| console.log(WRITERS[i] + " is " + AGES[i] + " old") |
There was a problem hiding this comment.
| console.log(WRITERS[i] + " is " + AGES[i] + " old") | |
| console.log(WRITERS[i] + " is " + AGES[i] + "years old") |
| "Tottenham Court Road" | ||
| ]; | ||
|
|
||
| for (i of tubeStations) |
There was a problem hiding this comment.
| for (i of tubeStations) | |
| for (const station of tubeStations) |
I think it will be better to use a meaningful variables names, it's easy to read and understand ("i" generally refers to index which is not the case here)
|
|
||
| function getTemperatureReport(cities) { | ||
| // TODO | ||
| function getTemperatureReport(cities) |
| function getRandomNumberGreaterThan50() | ||
| { | ||
| let total; | ||
| do | ||
| { | ||
| (total = generateRandomNumber()); | ||
| } | ||
| while (total <= 50); | ||
|
|
||
| return total; |
There was a problem hiding this comment.
I think the use of 'total' as the name of the variable creates a little confusion as we don't really calculate any total in this function
| function titleWithFewestWords(allArticleTitles) | ||
| { | ||
| const shorter = (left, right) => left.length <= right.length ? left : right; | ||
|
|
||
| return allArticleTitles.reduce(shorter); | ||
| } | ||
|
|
There was a problem hiding this comment.
Could you please add some comments to this function, I didn't really understand it?
| //https://jrsinclair.com/articles/2019/five-ways-to-average-with-js-reduce/ | ||
| function getAveragePrices(closingPricesForAllStocks) | ||
| { | ||
| //const reduce = r => i => a => a.reduce(r, i); | ||
| //conatiner = getting items => got items.reduce => add / length .map previous => round to 2 dec | ||
| const average = (closingPricesForAllStocks.map((array) => array.reduce((r, current) => r + current / array.length, 0))).map((element) => parseFloat(element.toFixed(2))); | ||
|
|
||
| return average; |
There was a problem hiding this comment.
Could you please delete unnecessary comments to make the code cleaner :D
| function getPriceChanges(closingPricesForAllStocks) | ||
| { | ||
| const PriceChange = (closingPricesForAllStocks.map((array) => array[array.length - 1] - array[0])).map((element) => parseFloat(element.toFixed(2))); | ||
|
|
||
| return PriceChange; |
There was a problem hiding this comment.
| function getPriceChanges(closingPricesForAllStocks) | |
| { | |
| const PriceChange = (closingPricesForAllStocks.map((array) => array[array.length - 1] - array[0])).map((element) => parseFloat(element.toFixed(2))); | |
| return PriceChange; | |
| function getPriceChanges(closingPricesForAllStocks) | |
| { | |
| const priceChange = closingPricesForAllStocks.map((array) => array[array.length - 1] - array[0]) | |
| const result = priceChange.map((element) => parseFloat(element.toFixed(2)); | |
| return result; |
It's better to use to variables to make code more readable
| return console.log(""); | ||
| } | ||
|
|
||
| for(let i = 1; i < n; i++) |
There was a problem hiding this comment.
Hi Kerim, I've looked through your code and it's great! One suggestion I have here however is using a while loop instead of a for loop.
Great work!
No description provided.