From e42c8d824815e606ce9e85ea3d4a31326e17b752 Mon Sep 17 00:00:00 2001 From: Ehdaa Munier <109866621+Ehdaa-Munier@users.noreply.github.com> Date: Fri, 10 Mar 2023 01:29:55 +0000 Subject: [PATCH 1/6] first try 1-weather-report --- 2-mandatory/1-weather-report.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/2-mandatory/1-weather-report.js b/2-mandatory/1-weather-report.js index dcc2bdb0..88363b58 100644 --- a/2-mandatory/1-weather-report.js +++ b/2-mandatory/1-weather-report.js @@ -12,9 +12,15 @@ */ function getTemperatureReport(cities) { + let cities = ["London", "Paris" ,"Barcelona" , "Dubai", "Mumbai", "Sao Paulo", "Lagos"]; + let temparature = [ 10 , 12 , 17 , 27 , 29 , 23 , 33 ]; + + // TODO } + return `The temperature in ${cities} is ${temparature} degrees`; + /* ======= TESTS - DO NOT MODIFY ===== */ From 57f094e62dac35750166303aa0384af746e5cbdd Mon Sep 17 00:00:00 2001 From: Ehdaa Munier <109866621+Ehdaa-Munier@users.noreply.github.com> Date: Sat, 11 Mar 2023 12:30:29 +0000 Subject: [PATCH 2/6] fix the weather report --- 2-mandatory/1-weather-report.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/2-mandatory/1-weather-report.js b/2-mandatory/1-weather-report.js index 88363b58..19ed6c36 100644 --- a/2-mandatory/1-weather-report.js +++ b/2-mandatory/1-weather-report.js @@ -12,15 +12,17 @@ */ function getTemperatureReport(cities) { - let cities = ["London", "Paris" ,"Barcelona" , "Dubai", "Mumbai", "Sao Paulo", "Lagos"]; - let temparature = [ 10 , 12 , 17 , 27 , 29 , 23 , 33 ]; + let report = []; + for (let city of cities) { + let temparature = temperatureService(city); + report.push( `The temperature in ${city} is ${temparature} degrees`); + - - // TODO + + } + return report; } - - return `The temperature in ${cities} is ${temparature} degrees`; - + /* ======= TESTS - DO NOT MODIFY ===== */ From c7625b10424b842bb3f75496473741b8c762586d Mon Sep 17 00:00:00 2001 From: Ehdaa Munier <109866621+Ehdaa-Munier@users.noreply.github.com> Date: Sun, 12 Mar 2023 17:00:00 +0000 Subject: [PATCH 3/6] fix third exercise --- 2-mandatory/2-financial-times.js | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/2-mandatory/2-financial-times.js b/2-mandatory/2-financial-times.js index 2ce6fb73..8443503c 100644 --- a/2-mandatory/2-financial-times.js +++ b/2-mandatory/2-financial-times.js @@ -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 + // TODO l + let headlines=[]; + for (let title of allArticleTitles); + if ( title.length <= 65){ + headlines.push (title) + } + return headlines; } /* @@ -14,6 +20,18 @@ function potentialHeadlines(allArticleTitles) { (you can assume words will always be seperated by a space) */ function titleWithFewestWords(allArticleTitles) { + let result = allArticleTitles[0]; + let resultlengh = result.split(' ').length; + for ( let i=1; i< allArticleTitles.length; i++ ){ + + let words = allArticleTitles[i].split(' '); + if (resultlengh > words.length){ + result= allArticleTitles[i] + resultlengh = words.length + + } + } + return result; // TODO } @@ -23,6 +41,14 @@ function titleWithFewestWords(allArticleTitles) { (Hint: remember that you can also loop through the characters of a string if you need to) */ function headlinesWithNumbers(allArticleTitles) { + + let headlines = []; + for (let title of allArticleTitles){ + if (/\d/.test(title)){ + headlines.push(title); + } + } + return headlines; // TODO } @@ -31,6 +57,7 @@ function headlinesWithNumbers(allArticleTitles) { Implement the function below to return this number - rounded to the nearest integer. */ function averageNumberOfCharacters(allArticleTitles) { +let allArticleTitles = []; // TODO } @@ -65,7 +92,7 @@ test("should return an empty array for empty input", () => { expect(potentialHeadlines([])).toEqual([]); }); -test("should return the title with the fewest words", () => { +test.only("should return the title with the fewest words", () => { expect(titleWithFewestWords(ARTICLE_TITLES)).toEqual("The three questions that dominate investment"); }); From bd5cd1cc2a77afe5eecc4c6a4122aea8a5023590 Mon Sep 17 00:00:00 2001 From: Ehdaa Munier <109866621+Ehdaa-Munier@users.noreply.github.com> Date: Tue, 14 Mar 2023 14:39:14 +0000 Subject: [PATCH 4/6] fix average prices --- 2-mandatory/2-financial-times.js | 2 +- 2-mandatory/3-stocks.js | 33 ++++++++++++++++++++++++++++++-- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/2-mandatory/2-financial-times.js b/2-mandatory/2-financial-times.js index 8443503c..319fdb6e 100644 --- a/2-mandatory/2-financial-times.js +++ b/2-mandatory/2-financial-times.js @@ -92,7 +92,7 @@ test("should return an empty array for empty input", () => { expect(potentialHeadlines([])).toEqual([]); }); -test.only("should return the title with the fewest words", () => { +test("should return the title with the fewest words", () => { expect(titleWithFewestWords(ARTICLE_TITLES)).toEqual("The three questions that dominate investment"); }); diff --git a/2-mandatory/3-stocks.js b/2-mandatory/3-stocks.js index 72d62f94..b3b31d27 100644 --- a/2-mandatory/3-stocks.js +++ b/2-mandatory/3-stocks.js @@ -34,8 +34,36 @@ const CLOSING_PRICES_LAST_5_DAYS_FOR_ALL_STOCKS = [ Functions can help with this! */ function getAveragePrices(closingPricesForAllStocks) { - // TODO + + let averagePrices = []; + for (let stockPrices of closingPricesForAllStocks){ + let sumOfPrices = 0; + for (let price of stockPrices) { + sumOfPrices = sumOfPrices + price; + } + let averagePrice = sumOfPrices / stockPrices.length; + let roundedAverage = Math.round(averagePrice * 100) / 100; + averagePrices.push(roundedAverage); + } + + + + return averagePrices; } + // TODO + + /* let averagePrice = []; + for (let i = 0; i < closingPricesForAllStocks.length; i++){ + let sum = 0; + for (let j = 0; j < closingPricesForAllStocks[i].lenght; j++){ + sum += closingPricesForAllStocks[i][j]; + } + averagePrice.push(Number((sum / closingPricesForAllStocks[i].lenght).toFixed(2))); + + } + return averagePrice; */ + + /* We also want to see what the change in price is from the first day to the last day for each stock. @@ -49,6 +77,7 @@ function getAveragePrices(closingPricesForAllStocks) { */ function getPriceChanges(closingPricesForAllStocks) { // TODO + return priceChange } /* @@ -69,7 +98,7 @@ function highestPriceDescriptions(closingPricesForAllStocks, stocks) { /* ======= TESTS - DO NOT MODIFY ===== */ -test("should return the average price for each stock", () => { +test.only("should return the average price for each stock", () => { expect(getAveragePrices(CLOSING_PRICES_LAST_5_DAYS_FOR_ALL_STOCKS)).toEqual( [176.89, 335.66, 3405.66, 2929.22, 1041.93] ); From 2781ca2cfaec2cd3d64acf6d73da3ca8005407db Mon Sep 17 00:00:00 2001 From: Ehdaa Munier <109866621+Ehdaa-Munier@users.noreply.github.com> Date: Tue, 14 Mar 2023 19:59:39 +0000 Subject: [PATCH 5/6] fix all stocks --- 2-mandatory/3-stocks.js | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/2-mandatory/3-stocks.js b/2-mandatory/3-stocks.js index b3b31d27..0fddd381 100644 --- a/2-mandatory/3-stocks.js +++ b/2-mandatory/3-stocks.js @@ -76,8 +76,16 @@ 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 - return priceChange + let priceChanges = []; + + for( let stockPrices of closingPricesForAllStocks){ + let startPrice = stockPrices[0] * 100; + let closePrice = stockPrices[stockPrices.length - 1] * 100; + priceChanges.push(math.round(closePrice - startPrice) / 100); + } + + + return priceChanges; } /* @@ -93,7 +101,27 @@ function getPriceChanges(closingPricesForAllStocks) { The price should be shown with exactly 2 decimal places. */ function highestPriceDescriptions(closingPricesForAllStocks, stocks) { - // TODO + let highestPriceStrings = []; + + + for(let i = 0; i< stocks.length; i++){ + let stockName = stocks[i].toUpperCase(); + let stockPrices = closingPricesForAllStocks[i]; + + let highestPrice; + for (let price of stockPrices){ + if (highestPrice == undefined || price > highestPrice){ + highestPrice = price; + } + } + highestPriceStrings.push(`The highest price of ${"stockName"} in the last 5 days was ${highestPrice.toFixed(2)}`); + } + + + + + + return highestPriceStrings; } From 27452d04b75770ab43a584545ef25474c213d6aa Mon Sep 17 00:00:00 2001 From: Ehdaa Munier <109866621+Ehdaa-Munier@users.noreply.github.com> Date: Tue, 14 Mar 2023 20:26:31 +0000 Subject: [PATCH 6/6] fix financial --- 2-mandatory/2-financial-times.js | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/2-mandatory/2-financial-times.js b/2-mandatory/2-financial-times.js index 319fdb6e..4eda6f63 100644 --- a/2-mandatory/2-financial-times.js +++ b/2-mandatory/2-financial-times.js @@ -7,10 +7,16 @@ function potentialHeadlines(allArticleTitles) { // TODO l let headlines=[]; - for (let title of allArticleTitles); - if ( title.length <= 65){ - headlines.push (title) + + + + for(let title of allArticleTitles) { + if(title.length <= 65) { + headlines.push(title); + } } + + return headlines; } @@ -57,9 +63,13 @@ function headlinesWithNumbers(allArticleTitles) { Implement the function below to return this number - rounded to the nearest integer. */ function averageNumberOfCharacters(allArticleTitles) { -let allArticleTitles = []; - // TODO + totalNumbers = 0; + for (let i = 0; i < allArticleTitles.length; i++){ + totalNumbers += allArticleTitles[i].length; + } + return Math.round(totalNumbers/allArticleTitles.length); } +