From f7c33cdceebd300274e01d802eddce8366d458b5 Mon Sep 17 00:00:00 2001 From: onurat <114289826+onurat@users.noreply.github.com> Date: Wed, 19 Apr 2023 00:57:19 +0100 Subject: [PATCH 01/14] Update 1-weather-report.js --- 2-mandatory/1-weather-report.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/2-mandatory/1-weather-report.js b/2-mandatory/1-weather-report.js index dcc2bdb0..4ca60481 100644 --- a/2-mandatory/1-weather-report.js +++ b/2-mandatory/1-weather-report.js @@ -12,7 +12,12 @@ */ function getTemperatureReport(cities) { - // TODO + var temparatureInCities = []; + + for (let i = 0; i < cities.length; i++) { + temparatureInCities.push("The temperature in " + cities[i] + "is " + temparature[i] + "degrees") + } + return temparatureInCities; } From 54f261a155e36aa738e136b3351d2184db6319b6 Mon Sep 17 00:00:00 2001 From: onurat <114289826+onurat@users.noreply.github.com> Date: Wed, 19 Apr 2023 23:06:12 +0100 Subject: [PATCH 02/14] Update 1-weather-report.js --- 2-mandatory/1-weather-report.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/2-mandatory/1-weather-report.js b/2-mandatory/1-weather-report.js index 4ca60481..af2a89c4 100644 --- a/2-mandatory/1-weather-report.js +++ b/2-mandatory/1-weather-report.js @@ -14,8 +14,9 @@ function getTemperatureReport(cities) { var temparatureInCities = []; - for (let i = 0; i < cities.length; i++) { - temparatureInCities.push("The temperature in " + cities[i] + "is " + temparature[i] + "degrees") + for (let i = 0; i < cities.length; i++) { + let temparature = temperatureService(cities[i]) + temparatureInCities.push(`The temperature in ${cities[i]} is ${temperature} degrees`) } return temparatureInCities; } From a302187e1e7a9007b3969a2f54231215d7ad4b65 Mon Sep 17 00:00:00 2001 From: onurat <114289826+onurat@users.noreply.github.com> Date: Wed, 19 Apr 2023 23:28:54 +0100 Subject: [PATCH 03/14] Update 2-financial-times.js --- 2-mandatory/2-financial-times.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/2-mandatory/2-financial-times.js b/2-mandatory/2-financial-times.js index 2ce6fb73..bb73a627 100644 --- a/2-mandatory/2-financial-times.js +++ b/2-mandatory/2-financial-times.js @@ -5,7 +5,15 @@ Implement the function below, which will return a new array containing only article titles which will fit. */ function potentialHeadlines(allArticleTitles) { - // TODO + var articleTitles = []; + + for (let i = 0; i < allArticleTitles.length; i++,){ + const collection = collect(allArticleTitles); + let length = 65; + console.log(collection.pull(i >= length )) + collection.push(articleTitles[i]) + + } } /* From 510a92ed23aec9647af16c7bdb05bc48864de548 Mon Sep 17 00:00:00 2001 From: onurat <114289826+onurat@users.noreply.github.com> Date: Wed, 19 Apr 2023 23:33:14 +0100 Subject: [PATCH 04/14] Update 2-financial-times.js --- 2-mandatory/2-financial-times.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/2-mandatory/2-financial-times.js b/2-mandatory/2-financial-times.js index bb73a627..4b916700 100644 --- a/2-mandatory/2-financial-times.js +++ b/2-mandatory/2-financial-times.js @@ -7,11 +7,10 @@ function potentialHeadlines(allArticleTitles) { var articleTitles = []; - for (let i = 0; i < allArticleTitles.length; i++,){ - const collection = collect(allArticleTitles); - let length = 65; - console.log(collection.pull(i >= length )) - collection.push(articleTitles[i]) + for (let i = 0; i < allArticleTitles.length; i++) { + let length = 65; + + } } From dd504b65872729a58fefb271c3e029db088050f6 Mon Sep 17 00:00:00 2001 From: onurat <114289826+onurat@users.noreply.github.com> Date: Thu, 20 Apr 2023 00:02:13 +0100 Subject: [PATCH 05/14] 2-mandatory/2-financial-times.js --- 2-mandatory/1-weather-report.js | 2 +- 2-mandatory/2-financial-times.js | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/2-mandatory/1-weather-report.js b/2-mandatory/1-weather-report.js index af2a89c4..44ce1027 100644 --- a/2-mandatory/1-weather-report.js +++ b/2-mandatory/1-weather-report.js @@ -16,7 +16,7 @@ function getTemperatureReport(cities) { for (let i = 0; i < cities.length; i++) { let temparature = temperatureService(cities[i]) - temparatureInCities.push(`The temperature in ${cities[i]} is ${temperature} degrees`) + temparatureInCities.push(`The temperature in ${cities[i]} is ${temparature} degrees`) } return temparatureInCities; } diff --git a/2-mandatory/2-financial-times.js b/2-mandatory/2-financial-times.js index 4b916700..ddc8dac6 100644 --- a/2-mandatory/2-financial-times.js +++ b/2-mandatory/2-financial-times.js @@ -8,8 +8,10 @@ function potentialHeadlines(allArticleTitles) { var articleTitles = []; for (let i = 0; i < allArticleTitles.length; i++) { - let length = 65; - + let lengthLimit = 65; + if (allArticleTitles.length[i] <= lengthLimit); + articleTitles.push(allArticleTitles[i]), + } From 0e49efdbe95da5a3dc102c6fe46d4d77c475894e Mon Sep 17 00:00:00 2001 From: onurat <114289826+onurat@users.noreply.github.com> Date: Thu, 20 Apr 2023 00:45:43 +0100 Subject: [PATCH 06/14] Update 2-financial-times.js --- 2-mandatory/2-financial-times.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/2-mandatory/2-financial-times.js b/2-mandatory/2-financial-times.js index ddc8dac6..d32fedc6 100644 --- a/2-mandatory/2-financial-times.js +++ b/2-mandatory/2-financial-times.js @@ -10,12 +10,13 @@ function potentialHeadlines(allArticleTitles) { for (let i = 0; i < allArticleTitles.length; i++) { let lengthLimit = 65; if (allArticleTitles.length[i] <= lengthLimit); - articleTitles.push(allArticleTitles[i]), + articleTitles.push(allArticleTitles[i] <= lengthLimit ); + + } +} - } -} /* The editor of the FT likes short headlines with only a few words! From 3e75ec1eae7b22b2ecb366c152912e789e1420e6 Mon Sep 17 00:00:00 2001 From: onurat <114289826+onurat@users.noreply.github.com> Date: Thu, 20 Apr 2023 00:51:24 +0100 Subject: [PATCH 07/14] Update 2-financial-times.js --- 2-mandatory/2-financial-times.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/2-mandatory/2-financial-times.js b/2-mandatory/2-financial-times.js index d32fedc6..d96431f9 100644 --- a/2-mandatory/2-financial-times.js +++ b/2-mandatory/2-financial-times.js @@ -8,9 +8,9 @@ function potentialHeadlines(allArticleTitles) { var articleTitles = []; for (let i = 0; i < allArticleTitles.length; i++) { - let lengthLimit = 65; - if (allArticleTitles.length[i] <= lengthLimit); - articleTitles.push(allArticleTitles[i] <= lengthLimit ); + const eachTitle = allArticleTitles[i]; + if (eachTitles.lenght <= 65); + } } From fff54875a6c87f03e4b1ee3dccb32b744a861b6e Mon Sep 17 00:00:00 2001 From: onurat <114289826+onurat@users.noreply.github.com> Date: Thu, 20 Apr 2023 00:53:34 +0100 Subject: [PATCH 08/14] Update 2-financial-times.js --- 2-mandatory/2-financial-times.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/2-mandatory/2-financial-times.js b/2-mandatory/2-financial-times.js index d96431f9..a50f33ff 100644 --- a/2-mandatory/2-financial-times.js +++ b/2-mandatory/2-financial-times.js @@ -9,10 +9,10 @@ function potentialHeadlines(allArticleTitles) { for (let i = 0; i < allArticleTitles.length; i++) { const eachTitle = allArticleTitles[i]; - if (eachTitles.lenght <= 65); - - + if (eachTitle.length <= 65); + articleTitles.push(eachTitle) } + return articleTitles; } From e16352c3a597c92d38e4d9f006b663112213f384 Mon Sep 17 00:00:00 2001 From: onurat <114289826+onurat@users.noreply.github.com> Date: Thu, 20 Apr 2023 01:35:46 +0100 Subject: [PATCH 09/14] Update 2-financial-times.js --- 2-mandatory/2-financial-times.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/2-mandatory/2-financial-times.js b/2-mandatory/2-financial-times.js index a50f33ff..3cda327f 100644 --- a/2-mandatory/2-financial-times.js +++ b/2-mandatory/2-financial-times.js @@ -23,8 +23,20 @@ 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) */ -function titleWithFewestWords(allArticleTitles) { - // TODO +function titleWithFewestWords(allArticleTitles){ + var lowest = Infinity; + var titleWithFewestWords; + + + for (var i = 0; i < allArticleTitles.length; i++) { + var words = allArticleTitles[i].split(" "); + if (words.length < lowest) { + lowest = words.length; + titleWithFewestWords = allArticleTitles[i]; + } + } + + return titleWithFewestWords; } /* From 7c205e8d160e1e9cce94408866eeed156009c4cd Mon Sep 17 00:00:00 2001 From: onurat <114289826+onurat@users.noreply.github.com> Date: Thu, 20 Apr 2023 01:37:03 +0100 Subject: [PATCH 10/14] Update 2-financial-times.js --- 2-mandatory/2-financial-times.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/2-mandatory/2-financial-times.js b/2-mandatory/2-financial-times.js index 3cda327f..57a3733e 100644 --- a/2-mandatory/2-financial-times.js +++ b/2-mandatory/2-financial-times.js @@ -24,20 +24,22 @@ function potentialHeadlines(allArticleTitles) { (you can assume words will always be seperated by a space) */ function titleWithFewestWords(allArticleTitles){ + var articleTitles = []; + var lowest = 0; + var lowest = Infinity; var titleWithFewestWords; - - - for (var i = 0; i < allArticleTitles.length; i++) { - var words = allArticleTitles[i].split(" "); - if (words.length < lowest) { + + for (var i = 0; i < allArticleTitles.length; i++) { + var words = allArticleTitles[i].split(" "); + if (words.length < lowest) { lowest = words.length; titleWithFewestWords = allArticleTitles[i]; } } - + return titleWithFewestWords; -} + } /* The editor of the FT has realised that headlines which have numbers in them get more clicks! From 00170a78386e265dfcd599de7a547fbed9c557ca Mon Sep 17 00:00:00 2001 From: onurat <114289826+onurat@users.noreply.github.com> Date: Fri, 21 Apr 2023 00:24:55 +0100 Subject: [PATCH 11/14] 2-mandatory\2-financial-times.js --- 2-mandatory/2-financial-times.js | 28 ++++++++++++++++++++-------- 2-mandatory/3-stocks.js | 2 +- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/2-mandatory/2-financial-times.js b/2-mandatory/2-financial-times.js index 57a3733e..1b9e4a4a 100644 --- a/2-mandatory/2-financial-times.js +++ b/2-mandatory/2-financial-times.js @@ -24,21 +24,20 @@ function potentialHeadlines(allArticleTitles) { (you can assume words will always be seperated by a space) */ function titleWithFewestWords(allArticleTitles){ - var articleTitles = []; - var lowest = 0; + var articleTitles = [] var lowest = Infinity; - var titleWithFewestWords; + var articleTitleWords; for (var i = 0; i < allArticleTitles.length; i++) { var words = allArticleTitles[i].split(" "); if (words.length < lowest) { lowest = words.length; - titleWithFewestWords = allArticleTitles[i]; + articleTitleWords = allArticleTitles[i]; } } - return titleWithFewestWords; + return articleTitleWords; } /* @@ -47,19 +46,32 @@ function titleWithFewestWords(allArticleTitles){ (Hint: remember that you can also loop through the characters of a string if you need to) */ function headlinesWithNumbers(allArticleTitles) { - // TODO -} + const titlesWithNumbers = allArticleTitles.filter(title => { + for (let i = 0; i < title.length; i++) { + if (!isNaN(title[i])) { + return true; + } + } + return false; + }); + return titlesWithNumbers; + } + + /* 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 + const articleLength = allArticleTitles.reduce((acc, articleTitle) => acc + articleTitle.length, 0); + const averageLength = articleLength / allArticleTitles.length; + return Math.round(averageLength); } + /* ======= List of Articles - DO NOT MODIFY ===== */ const ARTICLE_TITLES = [ "Streaming wars drive media groups to spend more than $100bn on new content", diff --git a/2-mandatory/3-stocks.js b/2-mandatory/3-stocks.js index 72d62f94..cc186099 100644 --- a/2-mandatory/3-stocks.js +++ b/2-mandatory/3-stocks.js @@ -34,7 +34,7 @@ const CLOSING_PRICES_LAST_5_DAYS_FOR_ALL_STOCKS = [ Functions can help with this! */ function getAveragePrices(closingPricesForAllStocks) { - // TODO + } /* From b81e30238525ec8ca0274155dc2d29aae971d7c1 Mon Sep 17 00:00:00 2001 From: onurat <114289826+onurat@users.noreply.github.com> Date: Fri, 21 Apr 2023 00:27:38 +0100 Subject: [PATCH 12/14] Update 2-financial-times.js --- 2-mandatory/2-financial-times.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/2-mandatory/2-financial-times.js b/2-mandatory/2-financial-times.js index 1b9e4a4a..96f00053 100644 --- a/2-mandatory/2-financial-times.js +++ b/2-mandatory/2-financial-times.js @@ -10,7 +10,7 @@ function potentialHeadlines(allArticleTitles) { for (let i = 0; i < allArticleTitles.length; i++) { const eachTitle = allArticleTitles[i]; if (eachTitle.length <= 65); - articleTitles.push(eachTitle) + articleTitles.push(eachTitle } return articleTitles; } From e52117f6bcc8b2524606aa37a176863d53c5bf92 Mon Sep 17 00:00:00 2001 From: onurat <114289826+onurat@users.noreply.github.com> Date: Fri, 21 Apr 2023 00:27:56 +0100 Subject: [PATCH 13/14] Update 2-financial-times.js --- 2-mandatory/2-financial-times.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/2-mandatory/2-financial-times.js b/2-mandatory/2-financial-times.js index 96f00053..1b9e4a4a 100644 --- a/2-mandatory/2-financial-times.js +++ b/2-mandatory/2-financial-times.js @@ -10,7 +10,7 @@ function potentialHeadlines(allArticleTitles) { for (let i = 0; i < allArticleTitles.length; i++) { const eachTitle = allArticleTitles[i]; if (eachTitle.length <= 65); - articleTitles.push(eachTitle + articleTitles.push(eachTitle) } return articleTitles; } From 1d317b346bc7c8b67deefe60a2769a9346989682 Mon Sep 17 00:00:00 2001 From: onurat <114289826+onurat@users.noreply.github.com> Date: Tue, 25 Apr 2023 12:16:35 +0100 Subject: [PATCH 14/14] 2-mandatory --- 2-mandatory/2-financial-times.js | 26 +++++++----------- 2-mandatory/3-stocks.js | 45 ++++++++++++++++++++++++++++---- 2 files changed, 50 insertions(+), 21 deletions(-) diff --git a/2-mandatory/2-financial-times.js b/2-mandatory/2-financial-times.js index 1b9e4a4a..2e55218c 100644 --- a/2-mandatory/2-financial-times.js +++ b/2-mandatory/2-financial-times.js @@ -8,12 +8,14 @@ function potentialHeadlines(allArticleTitles) { var articleTitles = []; for (let i = 0; i < allArticleTitles.length; i++) { - const eachTitle = allArticleTitles[i]; - if (eachTitle.length <= 65); - articleTitles.push(eachTitle) + const eachTitle = allArticleTitles[i]; + if (eachTitle.length <= 65) { + articleTitles.push(eachTitle); + } + } + + return articleTitles; } - return articleTitles; -} @@ -46,17 +48,9 @@ function titleWithFewestWords(allArticleTitles){ (Hint: remember that you can also loop through the characters of a string if you need to) */ function headlinesWithNumbers(allArticleTitles) { - const titlesWithNumbers = allArticleTitles.filter(title => { - for (let i = 0; i < title.length; i++) { - if (!isNaN(title[i])) { - return true; - } - } - return false; - }); - return titlesWithNumbers; - } - + const regex = /\d+/; + return allArticleTitles.filter(title => regex.test(title)); +} /* diff --git a/2-mandatory/3-stocks.js b/2-mandatory/3-stocks.js index cc186099..af5db2f0 100644 --- a/2-mandatory/3-stocks.js +++ b/2-mandatory/3-stocks.js @@ -35,7 +35,22 @@ const CLOSING_PRICES_LAST_5_DAYS_FOR_ALL_STOCKS = [ */ function getAveragePrices(closingPricesForAllStocks) { -} + const averageStocks = closingPricesForAllStocks.length; + const lastDays = closingPricesForAllStocks[0].length; + const averages = []; + + for (let i = 0; i < averageStocks; i++) { + let sum = 0; + for (let j = 0; j < lastDays; j++) { + sum += closingPricesForAllStocks[i][j]; + } + const average = sum / lastDays; + averages.push(parseFloat(average.toFixed(2))); + } + + return averages; + } + /* We also want to see what the change in price is from the first day to the last day for each stock. @@ -48,9 +63,19 @@ 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 -} + const averageStocks = closingPricesForAllStocks.length; + const changesInPrice = []; + + for (let i = 0; i < averageStocks; i++) { + const firstDayPrice = closingPricesForAllStocks[i][0]; + const lastDayPrice = closingPricesForAllStocks[i][closingPricesForAllStocks[i].length - 1]; + const priceChange = parseFloat((lastDayPrice - firstDayPrice).toFixed(2)); + changesInPrice.push(priceChange); + } + + return changesInPrice; + } /* As part of a financial report, we want to see what the highest price was for each stock in the last 5 days. Implement the below function, which @@ -64,8 +89,18 @@ function getPriceChanges(closingPricesForAllStocks) { The price should be shown with exactly 2 decimal places. */ function highestPriceDescriptions(closingPricesForAllStocks, stocks) { - // TODO -} + const highestPrices = []; + + for (let i = 0; i < stocks.length; i++) { + const stockPrices = closingPricesForAllStocks[i]; + const highestPrice = Math.max(...stockPrices).toFixed(2); + const stockName = stocks[i].toUpperCase(); + highestPrices.push(`The highest price of ${stockName} in the last 5 days was ${highestPrice}`); + } + + return highestPrices; + } + /* ======= TESTS - DO NOT MODIFY ===== */