-
-
Notifications
You must be signed in to change notification settings - Fork 279
WM4-Abdirahim-Hussein-JavaScript Core 1-Week-3 #94
base: main
Are you sure you want to change the base?
Changes from all commits
5500f8a
8937ccd
0565545
33f749c
2004472
ddb1f63
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,6 +27,9 @@ const AGES = [ | |
| ]; | ||
|
|
||
| // TODO - Write for loop code here | ||
| for (let i = 0; i <WRITERS.length; i++){ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see that You understand the for loop logic. Nicely done! |
||
| console.log(WRITERS[i] + ' is ' + AGES[i] + ' years old ') | ||
| } | ||
|
|
||
| /* | ||
| The output should look something like this: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,8 +13,12 @@ | |
|
|
||
| function getTemperatureReport(cities) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are very close to finishing this exercise. Please think over it and modify your solution in the way that You are going to pass these test cases: Tip: Check what exactly you are pushing in line 19 to the array. |
||
| // TODO | ||
| let temperature = []; | ||
| for (let i = 0; i < cities.length; i++) { | ||
| tem.push(`The temperature in ${cities[i]} is ${temperatureService(cities[i])} degrees`); | ||
| } | ||
| return temperature; | ||
| } | ||
|
|
||
|
|
||
| /* ======= TESTS - DO NOT MODIFY ===== */ | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,8 @@ | |
| */ | ||
| function potentialHeadlines(allArticleTitles) { | ||
| // TODO | ||
| const article = allArticleTitles.filter((article) => article.length <= 65); | ||
| return article; | ||
| } | ||
|
|
||
| /* | ||
|
|
@@ -15,15 +17,26 @@ function potentialHeadlines(allArticleTitles) { | |
| */ | ||
| function titleWithFewestWords(allArticleTitles) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are so close to solving the last two test cases. |
||
| // TODO | ||
| const outputOfArticle = allArticleTitles[0]; | ||
| for (let i = 0; i < allArticleTitles.length; i++) { | ||
| if ( | ||
| allArticleTitles[i].split(" ").length < outputOfArticle.split(" ").length | ||
| ) | ||
| outputOfArticle = allArticleTitles[i]; | ||
| } | ||
| return outputOfArticle; | ||
| } | ||
|
|
||
|
|
||
| /* | ||
| The editor of the FT has realised that headlines which have numbers in them get more clicks! | ||
| Implement the function below to return a new array containing all the headlines which contain a number. | ||
| (Hint: remember that you can also loop through the characters of a string if you need to) | ||
| */ | ||
| function headlinesWithNumbers(allArticleTitles) { | ||
| // TODO | ||
| const title = allArticleTitles.filter((article) => article.match(/(\d+)/)); | ||
| return title | ||
| } | ||
|
|
||
| /* | ||
|
|
@@ -32,6 +45,12 @@ function headlinesWithNumbers(allArticleTitles) { | |
| */ | ||
| function averageNumberOfCharacters(allArticleTitles) { | ||
| // TODO | ||
| const total = 0; | ||
| for (let title of allArticleTitles) { | ||
| total += title.length; | ||
| } | ||
| let average = total / allArticleTitles.length; | ||
| return Math.round(average); | ||
| } | ||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,6 +35,11 @@ const CLOSING_PRICES_LAST_5_DAYS_FOR_ALL_STOCKS = [ | |
| */ | ||
| function getAveragePrices(closingPricesForAllStocks) { | ||
| // TODO | ||
| return closingPricesForAllStocks.map((priceArr) => { | ||
| return Number( | ||
| (priceArr.reduce((tot, num) => tot + num) / priceArr.length).toFixed(2) | ||
| ); | ||
| }); | ||
| } | ||
|
|
||
| /* | ||
|
|
@@ -49,6 +54,9 @@ function getAveragePrices(closingPricesForAllStocks) { | |
| */ | ||
| function getPriceChanges(closingPricesForAllStocks) { | ||
| // TODO | ||
| return closingPricesForAllStocks.map((priceArr) => { | ||
| return Number((priceArr[priceArr.length - 1] - priceArr[0]).toFixed(2)); | ||
| }); | ||
| } | ||
|
|
||
| /* | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please finish last part of the exercise: |
||
|
|
@@ -65,6 +73,13 @@ function getPriceChanges(closingPricesForAllStocks) { | |
| */ | ||
| function highestPriceDescriptions(closingPricesForAllStocks, stocks) { | ||
| // TODO | ||
| let highestPriceDescriptions = []; | ||
| for (let i = 0; i < closingPricesForAllStocks.length; i++) { | ||
| highestPriceDescriptions.push(`The highest price of ${stocks[i].toUpperCase()} in the last 5 days was ${Math.max(...closingPricesForAllStocks[i] | ||
| ).toFixed(2)}` | ||
| ); | ||
| } | ||
| return highestPriceDescriptions; | ||
| } | ||
|
|
||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about using 'includes' method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.starts with July! Always learning! I have used the .includes method but it is nice to see other ways of doing it