ZA_2-Nishka_Kisten-JavaScript-Core-1-Coursework-Week3 - #65
Conversation
dschouw-CYF
left a comment
There was a problem hiding this comment.
Well done Nishka!
Really good use of array methods and the required looping constructs!
| array.push(i * 2); | ||
| i++; | ||
| } | ||
| return array.join(); |
|
|
||
| function evenNumbersSum(n) { | ||
| // TODO | ||
| let i = 0; |
There was a problem hiding this comment.
This is really well done.
Only comment is to please try and format/indent your code consistently. 👍
| "Tottenham Court Road" | ||
| ]; | ||
|
|
||
| for (let value of tubeStations) { |
There was a problem hiding this comment.
Code works perfectly fine. Try and name your variables with meaningful names ; names like value and val could be more descriptive to convey its actual use
|
|
||
| function getRandomNumberGreaterThan50() { | ||
| // TODO - implement using a do-while loop | ||
| let i ; |
| */ | ||
| function potentialHeadlines(allArticleTitles) { | ||
| // TODO | ||
| var result = allArticleTitles.filter((n) => n.length <= 65) |
There was a problem hiding this comment.
Good use of filter and the conditional to check for results before returning it.
What would happen if there were no articles with a length less than 65 and someone else was using your function ? Do you think your function should always return an array, even if it is an empty array?
There was a problem hiding this comment.
No.. It should probably return a message saying there are no articles that fit right?
| function titleWithFewestWords(allArticleTitles) { | ||
| // TODO | ||
| } | ||
| var fewestWords = allArticleTitles[0]; |
There was a problem hiding this comment.
Excellent algorithm with the for loop and initializing the fewestWords with the first element.
You could also use a for of loop, but your solution works!
There was a problem hiding this comment.
Will try it out though. Thanks!
| let sum = 0; | ||
| for(let element of closingPricesForAllStocks){ | ||
| sum = element.reduce((a, b) => a + b); | ||
| tot = sum / 5; |
There was a problem hiding this comment.
Good use of .reduce() function.
The constant literal 5 is an example of a "magic number" that should be avoided. What would happen to this calculation if the number of prices changed from 5 to any other number?
There was a problem hiding this comment.
It would be wrong.. Should I use .length? I will try and do it without magic numbers.
No description provided.