London Class 8 - Daniel Piga- JavaScript-Core-1-Coursework-Week3 London 8 - #3
London Class 8 - Daniel Piga- JavaScript-Core-1-Coursework-Week3 London 8#3pigos4 wants to merge 3 commits into
Conversation
DelroyGayle
left a comment
There was a problem hiding this comment.
Excellent coding.
I have a suggestion:
Seeing that you are using more advanced JavaScript than the majority of us.
Could you please add comments to your code so others (such as myself)
can learn and understand what your code is doing.
Thank you
| @@ -6,7 +6,13 @@ | |||
| */ | |||
|
|
|||
| function evenNumbers(n) { | |||
There was a problem hiding this comment.
Greetings Daniel
It has been a brain-growing experience reviewing your code. :)
Excellent.
However, I do have some suggestions:
It took me a while to figure out why you were using n * 2 and count % 2
Instead add '2' to your total instead of adding 1 each time.
That way, you can keep the limit as 'n' and there will be no need for the usage of %.
So have one variable for your total, another for your count; so that you have while (count < n)
Start of with total=zero. And then each time you repeat the loop, add 2.
There was a problem hiding this comment.
Hello Delroy,
Yes, I think your is a better solution only adding the two numbers to the string is easy.
Thanks
| @@ -7,9 +7,16 @@ | |||
| */ | |||
|
|
|||
| function evenNumbersSum(n) { | |||
There was a problem hiding this comment.
Dear Daniel
Unfortunately, this function does not work properly.
For example, the sum of the first n numbers when
n=1: should be 0,
n=2: 0 + 2 Should be 2
n=3: 0 + 2 + 4 Should be 6
n=4: 0 + 2 + 4 + 6 Should be 12
n=5: 0 + 2 + 4 + 6 + 8 Should be 20
However when I tested your function it gave the wrong answers for n=2,4,5.
So it needs to be redone.
Look at my other comments regarding evenNumbers(n) as a starting point.
There was a problem hiding this comment.
Yes thanks, is not working properly.
| "Yukiko Motoya", | ||
| ]; | ||
|
|
||
| const AGES = [59, 40, 41, 63, 49]; |
| } | ||
|
|
||
| // TODO Use a for-of loop to capitalise and output each letter in the string seperately. | ||
| let str = "codeyourfuture"; |
|
|
||
| function getTemperatureReport(cities) { | ||
| // TODO | ||
| return cities |
There was a problem hiding this comment.
Wow Daniel. .map and arrow notation!
Simply amazing
| @@ -34,9 +34,14 @@ const CLOSING_PRICES_LAST_5_DAYS_FOR_ALL_STOCKS = [ | |||
| Functions can help with this! | |||
| */ | |||
| @@ -48,7 +53,10 @@ function getAveragePrices(closingPricesForAllStocks) { | |||
| The price change value should be rounded to 2 decimal places, and should be a number (not a string) | |||
There was a problem hiding this comment.
Is the * 1 used to convert a string to a number?
There was a problem hiding this comment.
Yes because toFixed(2) returns a string
| @@ -64,31 +72,38 @@ function getPriceChanges(closingPricesForAllStocks) { | |||
| The price should be shown with exactly 2 decimal places. | |||
| */ | |||
| function highestPriceDescriptions(closingPricesForAllStocks, stocks) { | |||
| @@ -11,72 +11,75 @@ | |||
| */ | |||
|
|
|||
| function getHighestRatedInEachGenre(books) { | |||
| function generateFibonacciSequence(n) { | ||
| // TODO | ||
| } | ||
| function generateFibonacciSequence(num) { |
DelroyGayle
left a comment
There was a problem hiding this comment.
Daniel, it has been a pleasure looking at your code. You have given me many new ideas.
Thank you.
| do { | ||
| res = generateRandomNumber(); | ||
| } while (res <= 50); | ||
| if (res > 50) return res; |
There was a problem hiding this comment.
Hi Daniel. There is no need for the 'if' statement here since the while loop is finished when res is larger than 50
So you only need to do the return here.
| @@ -7,9 +7,16 @@ | |||
| */ | |||
|
|
|||
| function evenNumbersSum(n) { | |||
| @@ -6,7 +6,13 @@ | |||
| */ | |||
|
|
|||
| function evenNumbers(n) { | |||
kolomiets
left a comment
There was a problem hiding this comment.
Good job @pigos4 :)
map/filter/reduce are very good friends, you'll see them a lot in practice. The habit of thinking about programming problems as about operations over collections can get you very far - this is a very powerful technique.
| @@ -0,0 +1,5 @@ | |||
| { | |||
There was a problem hiding this comment.
Consider using .gitignore to simplify the management of local files you don't want to push for a review. This is a good practice to master :)
| function findFirstJulyBDay(birthdays) { | ||
| // TODO | ||
| for (let day of birthdays) { | ||
| if (day === "July 11th") return day; |
There was a problem hiding this comment.
This passes the test but technically this is not correct. If I update BIRTHDAY and add a new July date before "July 11th" - the code will not work correctly.
I'd expect it to be day. startsWith("July")
|
|
||
| function getTemperatureReport(cities) { | ||
| // TODO | ||
| return cities.map(function(city){ return`The temperature in ${city} is ${temperatureService(city)} degrees`} |
There was a problem hiding this comment.
Could be even more streamlined with lambdas :)
return cities.map(city =>The temperature in ${city} is ${temperatureService(city)} degrees
| */ | ||
| function titleWithFewestWords(allArticleTitles) { | ||
| // TODO | ||
| return allArticleTitles.sort((a, b) => a.split(" ").length - b.split(" ").length)[0]; |
There was a problem hiding this comment.
This may not be actually correct. You return the shortest title (meaning the title that contains the minimum number of letters). Instead, you need to find a title that has the fewest number of words.
| */ | ||
| function titleWithFewestWords(allArticleTitles) { | ||
| // TODO | ||
| return allArticleTitles.sort((a, b) => a.split(" ").length - b.split(" ").length)[0]; |
There was a problem hiding this comment.
Be careful with [0] - your function will crash for empty list of titles.
| let genres = books.reduce((acc,book) => { | ||
| //If the genre isn't in the initial value initial value is = to book or if the genre is in the | ||
| // initial value but is less than current value change the value to the current book | ||
| if (!acc[book.genre] || acc[book.genre].rating < book.rating)acc[book.genre] = book; |
There was a problem hiding this comment.
Some languages/programming styles allow if without curly braces or even with body on the same line. JavaScript style conventions generally discourage this. Do consider more "traditional" way of writing this:
if (!acc[book.genre] || acc[book.genre].rating < book.rating) {
acc[book.genre] = book;
}
return acc| // The list of numbers should start with 0. n is being passed in as a parameter. | ||
| // */ | ||
|
|
||
| function evenNumbers(n) { |
There was a problem hiding this comment.
Since you like operations over collections, how about this :)
function evenNumbers(n) {
console.log([...Array(n).keys()].map(x => x * 2).join(','))
}
No description provided.