Skip to content
This repository was archived by the owner on Jan 14, 2024. It is now read-only.

London Class 8 - Daniel Piga- JavaScript-Core-1-Coursework-Week3 London 8 - #3

Open
pigos4 wants to merge 3 commits into
CodeYourFuture:mainfrom
pigos4:main
Open

London Class 8 - Daniel Piga- JavaScript-Core-1-Coursework-Week3 London 8#3
pigos4 wants to merge 3 commits into
CodeYourFuture:mainfrom
pigos4:main

Conversation

@pigos4

@pigos4 pigos4 commented Jan 9, 2022

Copy link
Copy Markdown

No description provided.

@DelroyGayle DelroyGayle left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello Delroy,
Yes, I think your is a better solution only adding the two numbers to the string is easy.
Thanks

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are most welcome. Great work!

@@ -7,9 +7,16 @@
*/

function evenNumbersSum(n) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@pigos4 pigos4 Jan 10, 2022

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes thanks, is not working properly.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent!

"Yukiko Motoya",
];

const AGES = [59, 40, 41, 63, 49];

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent!

}

// TODO Use a for-of loop to capitalise and output each letter in the string seperately.
let str = "codeyourfuture";

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent!

Comment thread 2-mandatory/1-weather-report.js Outdated

function getTemperatureReport(cities) {
// TODO
return cities

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow Daniel. .map and arrow notation!
Simply amazing

Comment thread 2-mandatory/4-stocks.js
@@ -34,9 +34,14 @@ const CLOSING_PRICES_LAST_5_DAYS_FOR_ALL_STOCKS = [
Functions can help with this!
*/

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.map .reduce
Amazing!

Comment thread 2-mandatory/4-stocks.js
@@ -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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the * 1 used to convert a string to a number?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes because toFixed(2) returns a string

Comment thread 2-mandatory/4-stocks.js
@@ -64,31 +72,38 @@ function getPriceChanges(closingPricesForAllStocks) {
The price should be shown with exactly 2 decimal places.
*/
function highestPriceDescriptions(closingPricesForAllStocks, stocks) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing!

@@ -11,72 +11,75 @@
*/

function getHighestRatedInEachGenre(books) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Brilliant!

Comment thread 3-extra/3-fibonacci.js
function generateFibonacciSequence(n) {
// TODO
}
function generateFibonacciSequence(num) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent

@DelroyGayle DelroyGayle left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent!

@@ -6,7 +6,13 @@
*/

function evenNumbers(n) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are most welcome. Great work!

@kolomiets kolomiets left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread .vscode/settings.json
@@ -0,0 +1,5 @@
{

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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`}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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];

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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];

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@kolomiets kolomiets added the reviewed A mentor has reviewed this code label Jan 14, 2022
// The list of numbers should start with 0. n is being passed in as a parameter.
// */

function evenNumbers(n) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you like operations over collections, how about this :)

function evenNumbers(n) {
  console.log([...Array(n).keys()].map(x => x * 2).join(','))
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

reviewed A mentor has reviewed this code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants