-
-
Notifications
You must be signed in to change notification settings - Fork 279
London Class 8 - Irina Shilova - JavaScript-Core-1-Coursework-Week3 London 8 #14
base: main
Are you sure you want to change the base?
Changes from all commits
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 |
|---|---|---|
|
|
@@ -17,7 +17,12 @@ const BIRTHDAYS = [ | |
| ]; | ||
|
|
||
| function findFirstJulyBDay(birthdays) { | ||
| // TODO | ||
|
|
||
| let i = 0; | ||
| while (birthdays[i].substring(0, 4) !== "July") { | ||
|
Contributor
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. This is works and is perfectly fine. |
||
| i++; | ||
| } | ||
| return birthdays[i]; | ||
| } | ||
|
|
||
| console.log(findFirstJulyBDay(BIRTHDAYS)); // should output "July 11th" | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,13 @@ | |
| Implement the function below, which will return a new array containing only article titles which will fit. | ||
| */ | ||
| function potentialHeadlines(allArticleTitles) { | ||
| // TODO | ||
| let newArticle = []; | ||
|
Contributor
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. The implementation here is good. A couple of minor points - indentation in the body of the if-statement would improve readability. |
||
| for (let i = 0; i < allArticleTitles.length; i++) { | ||
| if (allArticleTitles[i].length <= 65) { | ||
| newArticle.push(allArticleTitles[i]) | ||
| } | ||
| } | ||
| return newArticle; | ||
| } | ||
|
|
||
| /* | ||
|
|
@@ -14,7 +20,17 @@ function potentialHeadlines(allArticleTitles) { | |
| (you can assume words will always be seperated by a space) | ||
| */ | ||
| function titleWithFewestWords(allArticleTitles) { | ||
| // TODO | ||
| let minWord = allArticleTitles[0].split(" ").length; | ||
| let j = 0; | ||
| for (let i = 0; i < allArticleTitles.length; i++ ) { | ||
| if (allArticleTitles[i].split(" ").length < minWord) { | ||
| minWord = allArticleTitles[i].split(" ").length; | ||
| j = i; | ||
| } | ||
|
|
||
| } | ||
| return allArticleTitles[j]; | ||
|
|
||
| } | ||
|
|
||
| /* | ||
|
|
@@ -23,15 +39,27 @@ function titleWithFewestWords(allArticleTitles) { | |
| (Hint: remember that you can also loop through the characters of a string if you need to) | ||
| */ | ||
| function headlinesWithNumbers(allArticleTitles) { | ||
| // TODO | ||
| let arrNum = []; | ||
| for (let i = 0; i < allArticleTitles.length; i++) { | ||
|
Contributor
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. This is an interesting implementation :) |
||
| for (let j = 0; j <= 9; j++) { | ||
| if (allArticleTitles[i].includes(j) && !arrNum.includes(allArticleTitles[i])) { | ||
| arrNum.push(allArticleTitles[i]); | ||
| } | ||
| } | ||
| } | ||
| return arrNum; | ||
| } | ||
|
|
||
| /* | ||
| The Financial Times wants to understand what the average number of characters in an article title is. | ||
| Implement the function below to return this number - rounded to the nearest integer. | ||
| */ | ||
| function averageNumberOfCharacters(allArticleTitles) { | ||
| // TODO | ||
| let sum = 0; | ||
| for (let i = 0; i < allArticleTitles.length; i++) { | ||
| sum = sum + allArticleTitles[i].length; | ||
| } | ||
| return Math.round(sum/allArticleTitles.length); | ||
| } | ||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,8 +34,16 @@ const CLOSING_PRICES_LAST_5_DAYS_FOR_ALL_STOCKS = [ | |
| Functions can help with this! | ||
| */ | ||
| function getAveragePrices(closingPricesForAllStocks) { | ||
| // TODO | ||
| } | ||
| let averageArr = []; | ||
|
Contributor
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. Nice implementation :) |
||
| for (let i = 0; i < closingPricesForAllStocks.length; i++) { | ||
| let sumAverage = 0; | ||
| for (let j = 0; j < closingPricesForAllStocks[i].length; j++) { | ||
| sumAverage = sumAverage + closingPricesForAllStocks[i][j]; | ||
| } | ||
| averageArr.push(Math.round(sumAverage/closingPricesForAllStocks[i].length * 100) / 100); | ||
| } | ||
| return averageArr; | ||
| } | ||
|
|
||
| /* | ||
| We also want to see what the change in price is from the first day to the last day for each stock. | ||
|
|
@@ -48,7 +56,11 @@ function getAveragePrices(closingPricesForAllStocks) { | |
| The price change value should be rounded to 2 decimal places, and should be a number (not a string) | ||
| */ | ||
| function getPriceChanges(closingPricesForAllStocks) { | ||
| // TODO | ||
| let priceChange = []; | ||
| for (let i = 0; i < closingPricesForAllStocks.length; i++) { | ||
| priceChange.push(Math.round((closingPricesForAllStocks[i][closingPricesForAllStocks[i].length-1] - closingPricesForAllStocks[i][0]) * 100) / 100); | ||
|
Contributor
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. This is good, but it would be a good idea to split this into multiple lines to improve the readability of the code. |
||
| } | ||
| return priceChange; | ||
| } | ||
|
|
||
| /* | ||
|
|
@@ -64,7 +76,18 @@ function getPriceChanges(closingPricesForAllStocks) { | |
| The price should be shown with exactly 2 decimal places. | ||
| */ | ||
| function highestPriceDescriptions(closingPricesForAllStocks, stocks) { | ||
| // TODO | ||
| let maxPrice = []; | ||
|
Contributor
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. Good job! |
||
| for (let i = 0; i < closingPricesForAllStocks.length; i++) { | ||
| let highestPrice = closingPricesForAllStocks[i][0]; | ||
| for (let j = 0; j < closingPricesForAllStocks[i].length; j++) { | ||
| if (closingPricesForAllStocks[i][j] > highestPrice) { | ||
| highestPrice = closingPricesForAllStocks[i][j]; | ||
| } | ||
| } | ||
| let str = "The highest price of " + stocks[i].toUpperCase() + " in the last 5 days was " + highestPrice.toFixed(2); | ||
| maxPrice.push(str); | ||
| } | ||
| return maxPrice; | ||
| } | ||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,7 +9,11 @@ | |
| */ | ||
|
|
||
| function factorial(input) { | ||
| // TODO | ||
| let production = 1; | ||
|
Contributor
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. Very good :) |
||
| for (let i = 1; i <=input; i++ ) { | ||
| production = production * i; | ||
| } | ||
| return production; | ||
| } | ||
|
|
||
| /* ======= TESTS - DO NOT MODIFY ===== */ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,7 +11,7 @@ | |
| */ | ||
|
|
||
| function getHighestRatedInEachGenre(books) { | ||
| // TODO | ||
|
|
||
| } | ||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,7 +14,12 @@ | |
| */ | ||
|
|
||
| function generateFibonacciSequence(n) { | ||
| // TODO | ||
| let fibArr = [0, 1]; | ||
|
Contributor
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. Also very good :) |
||
| for (let i = 0; i < n-2; i++ ) { | ||
| fibArr.push(fibArr[fibArr.length-1] + fibArr[fibArr.length-2]); | ||
|
|
||
| } | ||
| return fibArr; | ||
| } | ||
|
|
||
| /* ======= TESTS - DO NOT MODIFY ===== */ | ||
|
|
||
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.
Nice implementation! :)
Just keep an eye on indentation, to make the code more readable.