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

London10-Afsha-Hossain-JS-Core1-Coursework-Week3 #257

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

Afsha10
Copy link

@Afsha10 Afsha10 commented Mar 8, 2023

No description provided.

function titleWithFewestWords(allArticleTitles) {
let shortestHeadline;
Copy link

Choose a reason for hiding this comment

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

you could declare 'shortestHeadline' with const keyword instead let

Copy link
Contributor

Choose a reason for hiding this comment

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

I think shortestHeadline needs to be declared with let here as we are re-assigning a new value to it a few lines later.

Copy link

@SalihaPopal SalihaPopal left a comment

Choose a reason for hiding this comment

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

Well done!

@@ -12,6 +12,12 @@
*/

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks perfect 👍

@@ -5,6 +5,13 @@
Implement the function below, which will return a new array containing only article titles which will fit.
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

This look good!
For extra practice, can you try re-writing this using the filter array method?

Copy link

@SalihaPopal SalihaPopal left a comment

Choose a reason for hiding this comment

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

Great job!


// The output in the example below contains undefined because letters is an array with three elements, indexed from 0 to 2.
// When we try to access the element at index 3 (arr[3]), which is beyond the last index of the letters array, JavaScript returns undefined because there is no value at that index.

Choose a reason for hiding this comment

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

Nice explanation.

if (BIRTHDAYS[i].startsWith("July"))
return BIRTHDAYS[i];
i++;
}
}

console.log(findFirstJulyBDay(BIRTHDAYS)); // should output "July 11th"

Choose a reason for hiding this comment

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

Nice work, consice and good.

@@ -13,25 +20,72 @@ function potentialHeadlines(allArticleTitles) {
Implement the function below, which returns the title with the fewest words.
(you can assume words will always be seperated by a space)
*/
// ["The", "three", "questions", "that", "dominate", "investment"]
// fewestNumberOfWords = articleSplitter.length;

Copy link
Contributor

Choose a reason for hiding this comment

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

This is a very good attempt 👍 One small improvement:

  • Could you try doing this without using let fewestNumberOfWords = 1000;
  • You could either leave it uninitialised and check for undefined in your loop.. Or you could maybe initialise to the numberOfWords of the first title in the list.

// 1. We are getting array of string. We need to find if the string includes numbers.
// 2. Once we find a number, we will put the string to the new array.
// 3. We are going to return the new array. New array is string with numbers.

Copy link
Contributor

Choose a reason for hiding this comment

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

Very nice 👍

// 2. We need to find the number of Article titles.
// 3. We divide (total character) by (number of article titles).
// 4. Round it up

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks very good!

// 2. Divide the total price by the number of days i.e. 5



Copy link
Contributor

Choose a reason for hiding this comment

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

Very good variable names 😄
One question: Do you need to re-calculate the average each time through the loop? Maybe it's enough to just calculate the average once at the end?

@@ -48,7 +64,13 @@ function getAveragePrices(closingPricesForAllStocks) {
The price change value should be rounded to 2 decimal places, and should be a number (not a string)
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice!
One question: Will this code - closingPricesEachcompany[4] - closingPricesEachcompany[0] - still work if we have more than 5 prices in each array? Or less than 5 prices?
Can you think of how to make sure this works for any numbers of prices?

// }
// }
// arrayWithHighestValue.push(highestPrice);

Copy link
Contributor

Choose a reason for hiding this comment

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

This was a tough one!
Well done for completing it 👏

@moneyinthesky
Copy link
Contributor

Great job on this coursework 👏

@moneyinthesky moneyinthesky added the reviewed A mentor has reviewed this code label Mar 15, 2023
@SalihaPopal
Copy link

Thank you for your consideration and comments. I am going to apple what have you recommended me regarding some exercises.

Afsha10 added 2 commits March 22, 2023 00:20
We checked if we have an array that is the same length as the number of cities passed in.
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.

4 participants