-
-
Notifications
You must be signed in to change notification settings - Fork 280
London10-Afsha-Hossain-JS-Core1-Coursework-Week3 #257
base: main
Are you sure you want to change the base?
Changes from 4 commits
017ff7b
a5138d4
de3fc86
e32cf5f
0c6af51
c1d359d
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 |
|---|---|---|
|
|
@@ -16,8 +16,14 @@ const BIRTHDAYS = [ | |
| "November 15th" | ||
| ]; | ||
|
|
||
| function findFirstJulyBDay(birthdays) { | ||
| function findFirstJulyBDay(BIRTHDAYS) { | ||
| // TODO | ||
| let i = 0; | ||
| while (i < BIRTHDAYS.length) { | ||
| if (BIRTHDAYS[i].startsWith("July")) | ||
| return BIRTHDAYS[i]; | ||
| i++; | ||
| } | ||
| } | ||
|
|
||
| console.log(findFirstJulyBDay(BIRTHDAYS)); // should output "July 11th" | ||
|
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 work, consice and good. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,12 @@ | |
| */ | ||
|
|
||
|
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. Looks perfect 👍 |
||
| function getTemperatureReport(cities) { | ||
| let arr = []; | ||
| for (let city of cities) { | ||
| let weatherReport = `The temperature in ${city} is ${temperatureService(city)} degrees`; | ||
| arr.push(weatherReport); | ||
| } | ||
| return arr; | ||
| // TODO | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,13 @@ | |
| Implement the function below, which will return a new array containing only article titles which will fit. | ||
| */ | ||
|
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 look good! |
||
| function potentialHeadlines(allArticleTitles) { | ||
| let newArray = []; | ||
| for (let item of allArticleTitles) { | ||
| if (item.length <= 65) { | ||
| newArray.push(item); | ||
| } | ||
| } | ||
| return newArray; | ||
| // TODO | ||
| } | ||
|
|
||
|
|
@@ -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; | ||
|
|
||
|
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 a very good attempt 👍 One small improvement:
|
||
| function titleWithFewestWords(allArticleTitles) { | ||
| let shortestHeadline; | ||
|
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 could declare 'shortestHeadline' with const keyword instead let
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. I think |
||
| let fewestNumberOfWords = 1000; | ||
|
|
||
| for (let headline of allArticleTitles) { | ||
| let splitArticleTitle = (headline.split(" ")); | ||
| if (splitArticleTitle.length < fewestNumberOfWords) { | ||
| fewestNumberOfWords = splitArticleTitle.length; | ||
| shortestHeadline = headline; | ||
| } | ||
| } | ||
| return shortestHeadline; | ||
| // TODO | ||
| // loop through the headlines | ||
| // find number words in the headline | ||
| // find number of words in title | ||
| // compare the number with | ||
| } | ||
|
|
||
|
|
||
| /* | ||
| 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) | ||
| */ | ||
|
|
||
| // 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. | ||
|
|
||
|
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 nice 👍 |
||
| function headlinesWithNumbers(allArticleTitles) { | ||
| let newArrayWithNum = []; | ||
| for (const title of allArticleTitles) { | ||
| if (/\d/.test(title)) { | ||
| newArrayWithNum.push(title); | ||
| } | ||
| } | ||
|
|
||
| return newArrayWithNum; | ||
| // TODO | ||
| } | ||
|
|
||
| // for (character of title) { | ||
| // if (character.includes(Number)) { | ||
| // newArrayWithNum.push(title) | ||
| // } | ||
|
|
||
| /* | ||
| 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. | ||
| */ | ||
| // 1. We find total characters | ||
| // 2. We need to find the number of Article titles. | ||
| // 3. We divide (total character) by (number of article titles). | ||
| // 4. Round it up | ||
|
|
||
|
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. Looks very good! |
||
| function averageNumberOfCharacters(allArticleTitles) { | ||
| // TODO | ||
| let totalCharacter = 0; | ||
| for (let item of allArticleTitles) { | ||
| totalCharacter = totalCharacter + item.length; | ||
| } | ||
| return Math.round(totalCharacter / allArticleTitles.length); | ||
| } | ||
|
|
||
|
|
||
|
|
@@ -50,6 +104,7 @@ const ARTICLE_TITLES = [ | |
| "Brussels urges Chile's incoming president to endorse EU trade deal", | ||
| ]; | ||
|
|
||
|
|
||
| /* ======= TESTS - DO NOT MODIFY ===== */ | ||
|
|
||
| test("should only return potential headlines", () => { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,8 +33,24 @@ const CLOSING_PRICES_LAST_5_DAYS_FOR_ALL_STOCKS = [ | |
| Solve the smaller problems, and then build those solutions back up to solve the larger problem. | ||
| Functions can help with this! | ||
| */ | ||
|
|
||
| // 1. Find the total price of each company stocks in the last 5 days | ||
| // 2. Divide the total price by the number of days i.e. 5 | ||
|
|
||
|
|
||
|
|
||
|
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 variable names 😄 |
||
| function getAveragePrices(closingPricesForAllStocks) { | ||
| // TODO | ||
| let arrayOfAverageValues = []; | ||
| for (let closingPriceEachCompany of closingPricesForAllStocks) { | ||
| let sumOfClosingPriceEachCompany = 0; | ||
| for (i = 0; i < closingPriceEachCompany.length; i++) { | ||
| sumOfClosingPriceEachCompany = sumOfClosingPriceEachCompany + closingPriceEachCompany[i]; | ||
| averagePriceEachCompany = (sumOfClosingPriceEachCompany / closingPriceEachCompany.length).toFixed(2); | ||
| } | ||
| averagePricesNumberType = parseFloat(averagePriceEachCompany); | ||
| arrayOfAverageValues.push(averagePricesNumberType); | ||
| } | ||
| return arrayOfAverageValues; | ||
| } | ||
|
|
||
| /* | ||
|
|
@@ -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) | ||
| */ | ||
|
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! |
||
| function getPriceChanges(closingPricesForAllStocks) { | ||
| // TODO | ||
| let newPriceChangeArray = []; | ||
| for (let closingPricesEachcompany of closingPricesForAllStocks) { | ||
| let priceChange = (closingPricesEachcompany[4] - closingPricesEachcompany[0]).toFixed(2); | ||
| let priceChangeValues = parseFloat(priceChange); | ||
| newPriceChangeArray.push(priceChangeValues); | ||
| } | ||
| return newPriceChangeArray; | ||
| } | ||
|
|
||
| /* | ||
|
|
@@ -63,9 +85,35 @@ function getPriceChanges(closingPricesForAllStocks) { | |
| The stock ticker should be capitalised. | ||
| The price should be shown with exactly 2 decimal places. | ||
| */ | ||
| function highestPriceDescriptions(closingPricesForAllStocks, stocks) { | ||
| // TODO | ||
| } | ||
|
|
||
| // for (i = 0; i < closingPricesForAllStocks.length; i++) { | ||
| // let highestPrice = 0; | ||
| // for (let companyPriceArray of closingPricesForAllStocks) { | ||
| // if (companyPriceArray[i] > highestPrice) { | ||
| // highestPrice = companyPriceArray[i]; | ||
| // } | ||
| // } | ||
| // arrayWithHighestValue.push(highestPrice); | ||
|
|
||
|
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 was a tough one! |
||
| function highestPriceDescriptions(closingPricesForAllStocks, stocks) { | ||
| let highestCompanyStockPrices = []; | ||
| let namesOfCompanies = []; | ||
| let highestPrice = 0; | ||
| for (i = 0; i < closingPricesForAllStocks.length; i++) { | ||
| for (let closingPricePerDay of closingPricesForAllStocks[i]) { | ||
| if (closingPricePerDay > highestPrice) { | ||
| highestPrice = closingPricePerDay; | ||
| } | ||
| } | ||
| let upperStock = stocks[i].toUpperCase(); | ||
| highestCompanyStockPrices.push( | ||
| `The highest price of ${upperStock} in the last 5 days was ${highestPrice.toFixed(2)}`); | ||
| highestPrice = 0; | ||
| } | ||
| return highestCompanyStockPrices; | ||
| // return `The highest price of ${stocks} in the last 5 days was ${arrayWithHighestValue[i]}`; | ||
| } | ||
|
|
||
|
|
||
|
|
||
| /* ======= TESTS - DO NOT MODIFY ===== */ | ||
|
|
@@ -81,7 +129,7 @@ test("should return the price change for each stock", () => { | |
| ); | ||
| }); | ||
|
|
||
| test("should return a description of the highest price for each stock", () => { | ||
| test.only("should return a description of the highest price for each stock", () => { | ||
| expect(highestPriceDescriptions(CLOSING_PRICES_LAST_5_DAYS_FOR_ALL_STOCKS, STOCKS)).toEqual( | ||
| [ | ||
| "The highest price of AAPL in the last 5 days was 180.33", | ||
|
|
||
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 explanation.