From e9ff877466d3a0b03d111877f7ff16f7c417cdcf Mon Sep 17 00:00:00 2001 From: Mpanasetckiy Date: Mon, 20 Feb 2023 14:25:39 +0000 Subject: [PATCH 1/8] weather report done --- 2-mandatory/1-weather-report.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/2-mandatory/1-weather-report.js b/2-mandatory/1-weather-report.js index dcc2bdb0..93d69a40 100644 --- a/2-mandatory/1-weather-report.js +++ b/2-mandatory/1-weather-report.js @@ -13,6 +13,15 @@ function getTemperatureReport(cities) { // TODO + const temperatureReport = []; + + for(let i = 0; i < cities.length; i++) { + const temperature = temperatureService(cities[i]); + + temperatureReport.push(`The temperature in ${cities[i]} is ${temperature} degrees`); + } + + return temperatureReport; } From d42c6ff090f90fa3a3d1ce914479f5a1713d1dfb Mon Sep 17 00:00:00 2001 From: Mpanasetckiy Date: Mon, 20 Feb 2023 21:24:37 +0000 Subject: [PATCH 2/8] FT first two --- 2-mandatory/2-financial-times.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/2-mandatory/2-financial-times.js b/2-mandatory/2-financial-times.js index 2ce6fb73..d5930140 100644 --- a/2-mandatory/2-financial-times.js +++ b/2-mandatory/2-financial-times.js @@ -6,15 +6,28 @@ */ function potentialHeadlines(allArticleTitles) { // TODO + const headTitle = allArticleTitles.filter(title => title.length < 65); + + return headTitle; + } /* The editor of the FT likes short headlines with only a few words! Implement the function below, which returns the title with the fewest words. - (you can assume words will always be seperated by a space) + (you can assume words will always be separated by a space) */ function titleWithFewestWords(allArticleTitles) { // TODO + let shortestTitle = allArticleTitles[0]; + console.log(allArticleTitles[0]) + for (let i = 0; i < allArticleTitles.length; i++) { + const currentTitle = allArticleTitles[i]; + if (currentTitle.length < shortestTitle.length) { + shortestTitle = currentTitle + } + } + return shortestTitle; } /* From 4325719ab73c330b28cdc66ddf16dfc63b06fbac Mon Sep 17 00:00:00 2001 From: Mpanasetckiy Date: Mon, 20 Feb 2023 22:17:25 +0000 Subject: [PATCH 3/8] mandatory 2 done --- 2-mandatory/2-financial-times.js | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/2-mandatory/2-financial-times.js b/2-mandatory/2-financial-times.js index d5930140..3b4ab52a 100644 --- a/2-mandatory/2-financial-times.js +++ b/2-mandatory/2-financial-times.js @@ -20,7 +20,7 @@ function potentialHeadlines(allArticleTitles) { function titleWithFewestWords(allArticleTitles) { // TODO let shortestTitle = allArticleTitles[0]; - console.log(allArticleTitles[0]) + for (let i = 0; i < allArticleTitles.length; i++) { const currentTitle = allArticleTitles[i]; if (currentTitle.length < shortestTitle.length) { @@ -37,6 +37,16 @@ function titleWithFewestWords(allArticleTitles) { */ function headlinesWithNumbers(allArticleTitles) { // TODO + const titlesWithNumbers = []; + for (let i = 0; i < allArticleTitles.length; i++) { + const hasNumber = /\d/.test(allArticleTitles[i]) + + if (hasNumber) { + titlesWithNumbers.push(allArticleTitles[i]); + + } + } + return titlesWithNumbers; } /* @@ -45,6 +55,15 @@ function headlinesWithNumbers(allArticleTitles) { */ function averageNumberOfCharacters(allArticleTitles) { // TODO + const numberOfTitles = allArticleTitles.length; + let numberOfCharacters = 0; + + for (let i = 0; i < numberOfTitles; i++) { + numberOfCharacters += allArticleTitles[i].length; + } + + return Math.round(numberOfCharacters / numberOfTitles); + } From 5f9009abe4ef3b1979fa2e1bf612c17e5a1fd86e Mon Sep 17 00:00:00 2001 From: Mpanasetckiy Date: Tue, 21 Feb 2023 03:16:36 +0000 Subject: [PATCH 4/8] mandatory done --- 2-mandatory/3-stocks.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/2-mandatory/3-stocks.js b/2-mandatory/3-stocks.js index 72d62f94..b74b8c91 100644 --- a/2-mandatory/3-stocks.js +++ b/2-mandatory/3-stocks.js @@ -35,6 +35,14 @@ const CLOSING_PRICES_LAST_5_DAYS_FOR_ALL_STOCKS = [ */ function getAveragePrices(closingPricesForAllStocks) { // TODO + let currentStock = []; + for (let i = 0; i < closingPricesForAllStocks.length; i++) { + const numberOfStocks = closingPricesForAllStocks[i].length; + const sumOfCurrentStock = closingPricesForAllStocks[i].reduce((accumulator, currentValue) => accumulator + currentValue, 0); + const roundedStock = Math.round((sumOfCurrentStock / numberOfStocks) * 100) / 100; + currentStock.push(roundedStock); + } + return currentStock; } /* @@ -49,6 +57,17 @@ function getAveragePrices(closingPricesForAllStocks) { */ function getPriceChanges(closingPricesForAllStocks) { // TODO + let closingPrices = []; + + for (let i = 0; i < closingPricesForAllStocks.length; i++) { + const numberOfPrices = closingPricesForAllStocks[i].length - 1; + const firstDay = closingPricesForAllStocks[i].at(0); + const lastDay = closingPricesForAllStocks[i].at(numberOfPrices); + const priceChange = Math.round((lastDay - firstDay) * 100) / 100; + + closingPrices.push(priceChange); + } + return closingPrices; } /* @@ -65,6 +84,17 @@ function getPriceChanges(closingPricesForAllStocks) { */ function highestPriceDescriptions(closingPricesForAllStocks, stocks) { // TODO + let allHighestPrices = []; + for (let i = 0; i < closingPricesForAllStocks.length; i++) { + const stockName = stocks[i].toUpperCase(); + const stockPrices = closingPricesForAllStocks[i]; + const highestPrice = Math.max(...stockPrices).toFixed(2); + + allHighestPrices.push(`The highest price of ${stockName} in the last 5 days was ${highestPrice}`) + + } + + return allHighestPrices; } From ccc84389288fc6484c05de82d49c279ee2715148 Mon Sep 17 00:00:00 2001 From: Mpanasetckiy Date: Tue, 21 Feb 2023 03:51:45 +0000 Subject: [PATCH 5/8] exercises done --- 1-exercises/B-array-literals/exercise.js | 4 ++-- 1-exercises/C-array-get-set/exercise.js | 4 ++-- 1-exercises/C-array-get-set/exercises2.js | 2 +- 1-exercises/D-for-loop/exercise.js | 4 +++- 1-exercises/E-while-loop-with-array/exercise.js | 8 ++++++++ 2-mandatory/3-stocks.js | 8 ++++---- 6 files changed, 20 insertions(+), 10 deletions(-) diff --git a/1-exercises/B-array-literals/exercise.js b/1-exercises/B-array-literals/exercise.js index 51eba5cc..0062c63b 100644 --- a/1-exercises/B-array-literals/exercise.js +++ b/1-exercises/B-array-literals/exercise.js @@ -4,8 +4,8 @@ Declare some variables assigned to arrays of values */ -let numbers = []; // add numbers from 1 to 10 into this array -let mentors; // Create an array with the names of the mentors: Daniel, Irina and Rares +let numbers = [1,2,3,4,5,6,7,8,9,10]; // add numbers from 1 to 10 into this array +let mentors = ["Daniel", "Irina", "Rares"]; // Create an array with the names of the mentors: Daniel, Irina and Rares /* DO NOT EDIT BELOW THIS LINE diff --git a/1-exercises/C-array-get-set/exercise.js b/1-exercises/C-array-get-set/exercise.js index 5ca911d5..3e97995e 100644 --- a/1-exercises/C-array-get-set/exercise.js +++ b/1-exercises/C-array-get-set/exercise.js @@ -5,11 +5,11 @@ */ function first(arr) { - return; // complete this statement + return arr[0]; // complete this statement } function last(arr) { - return; // complete this statement + return arr[arr.length -1]; // complete this statement } /* diff --git a/1-exercises/C-array-get-set/exercises2.js b/1-exercises/C-array-get-set/exercises2.js index 6b6b007a..36d9c411 100644 --- a/1-exercises/C-array-get-set/exercises2.js +++ b/1-exercises/C-array-get-set/exercises2.js @@ -7,7 +7,7 @@ */ let numbers = [1, 2, 3]; // Don't change this array literal declaration - +numbers.push(4); /* DO NOT EDIT BELOW THIS LINE --------------------------- */ diff --git a/1-exercises/D-for-loop/exercise.js b/1-exercises/D-for-loop/exercise.js index 081002b2..1809a952 100644 --- a/1-exercises/D-for-loop/exercise.js +++ b/1-exercises/D-for-loop/exercise.js @@ -25,7 +25,9 @@ const AGES = [ 63, 49 ]; - +for (let i = 0; i < WRITERS.length; i++) { + console.log(`${WRITERS[i]} is ${AGES[i]} years old`); +} // TODO - Write for loop code here /* diff --git a/1-exercises/E-while-loop-with-array/exercise.js b/1-exercises/E-while-loop-with-array/exercise.js index d584cd75..880a4591 100644 --- a/1-exercises/E-while-loop-with-array/exercise.js +++ b/1-exercises/E-while-loop-with-array/exercise.js @@ -18,6 +18,14 @@ const BIRTHDAYS = [ function findFirstJulyBDay(birthdays) { // TODO + let i = 0; + while (i < birthdays.length) { + const birthday = birthdays[i]; + if (birthday.includes("July")) { + return birthday; + } + i++; + } } console.log(findFirstJulyBDay(BIRTHDAYS)); // should output "July 11th" diff --git a/2-mandatory/3-stocks.js b/2-mandatory/3-stocks.js index b74b8c91..768cde34 100644 --- a/2-mandatory/3-stocks.js +++ b/2-mandatory/3-stocks.js @@ -84,16 +84,16 @@ function getPriceChanges(closingPricesForAllStocks) { */ function highestPriceDescriptions(closingPricesForAllStocks, stocks) { // TODO - let allHighestPrices = []; + let allHighestPrices = []; for (let i = 0; i < closingPricesForAllStocks.length; i++) { const stockName = stocks[i].toUpperCase(); const stockPrices = closingPricesForAllStocks[i]; const highestPrice = Math.max(...stockPrices).toFixed(2); - + allHighestPrices.push(`The highest price of ${stockName} in the last 5 days was ${highestPrice}`) - + } - + return allHighestPrices; } From 37b53131e088a523aab1384d0377eef6cb2cb11e Mon Sep 17 00:00:00 2001 From: Mpanasetckiy Date: Tue, 21 Feb 2023 13:43:27 +0000 Subject: [PATCH 6/8] extras done --- 3-extra/1-radio-stations.js | 15 ++++++++++++++- 3-extra/2-array-of-objects.js | 12 ++++++++++++ 3-extra/3-fibonacci.js | 7 +++++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/3-extra/1-radio-stations.js b/3-extra/1-radio-stations.js index 577076e9..8c244328 100644 --- a/3-extra/1-radio-stations.js +++ b/3-extra/1-radio-stations.js @@ -14,7 +14,16 @@ */ // `getAllFrequencies` goes here +function getAllFrequencies() { + const allFrequencies = [ + 87, 88, 89, 90, 91, 92, + 93, 94, 95, 96, 97, 98, + 99, 100, 101, 102, 103, + 104, 105, 106, 107, 108, + ] + return allFrequencies; +} /** * Next, let's write a function that gives us only the frequencies that are radio stations. * Call this function `getStations`. @@ -25,7 +34,11 @@ * - Return only the frequencies that are radio stations. */ // `getStations` goes here - +function getStations() { + const allFrequencies = getAllFrequencies(); + const stations = allFrequencies.filter(isRadioStation); + return stations; +} /* * ======= TESTS - DO NOT MODIFY ======= * Note: You are not expected to understand everything below this comment! diff --git a/3-extra/2-array-of-objects.js b/3-extra/2-array-of-objects.js index ee57960f..b028ab7f 100644 --- a/3-extra/2-array-of-objects.js +++ b/3-extra/2-array-of-objects.js @@ -12,6 +12,18 @@ function getHighestRatedInEachGenre(books) { // TODO + const highestRatedBooks = {}; + for (const book of books) { + const { title, genre, rating } = book; + + if (highestRatedBooks[genre] === undefined || rating > highestRatedBooks[genre].rating) { + highestRatedBooks[genre] = { title, rating }; + } + } + const highestRatedTitlesByGenre = Object.values(highestRatedBooks).map(book => book.title); + + return highestRatedTitlesByGenre; + } diff --git a/3-extra/3-fibonacci.js b/3-extra/3-fibonacci.js index 9ef9aec7..fac6f97b 100644 --- a/3-extra/3-fibonacci.js +++ b/3-extra/3-fibonacci.js @@ -15,6 +15,13 @@ function generateFibonacciSequence(n) { // TODO + const sequence = [0, 1]; + + for (let i = 2; i < n; i++) { + sequence.push(sequence[i - 1] + sequence[i - 2]); + } + + return sequence; } /* ======= TESTS - DO NOT MODIFY ===== */ From 7df0dd1c2a102505a5cd6b83a91effcd26287706 Mon Sep 17 00:00:00 2001 From: Mpanasetckiy Date: Mon, 6 Mar 2023 15:22:29 +0000 Subject: [PATCH 7/8] refactoring --- 2-mandatory/2-financial-times.js | 23 +++-------------------- 3-extra/2-array-of-objects.js | 2 +- 2 files changed, 4 insertions(+), 21 deletions(-) diff --git a/2-mandatory/2-financial-times.js b/2-mandatory/2-financial-times.js index 3b4ab52a..867832d0 100644 --- a/2-mandatory/2-financial-times.js +++ b/2-mandatory/2-financial-times.js @@ -7,9 +7,7 @@ function potentialHeadlines(allArticleTitles) { // TODO const headTitle = allArticleTitles.filter(title => title.length < 65); - return headTitle; - } /* @@ -37,16 +35,7 @@ function titleWithFewestWords(allArticleTitles) { */ function headlinesWithNumbers(allArticleTitles) { // TODO - const titlesWithNumbers = []; - for (let i = 0; i < allArticleTitles.length; i++) { - const hasNumber = /\d/.test(allArticleTitles[i]) - - if (hasNumber) { - titlesWithNumbers.push(allArticleTitles[i]); - - } - } - return titlesWithNumbers; + return allArticleTitles.filter(title => /\d/.test(title)); } /* @@ -55,14 +44,8 @@ function headlinesWithNumbers(allArticleTitles) { */ function averageNumberOfCharacters(allArticleTitles) { // TODO - const numberOfTitles = allArticleTitles.length; - let numberOfCharacters = 0; - - for (let i = 0; i < numberOfTitles; i++) { - numberOfCharacters += allArticleTitles[i].length; - } - - return Math.round(numberOfCharacters / numberOfTitles); + const articleSum = allArticleTitles.reduce((acc, val) => acc + val.length, 0); + return Math.round(articleSum / allArticleTitles.length) } diff --git a/3-extra/2-array-of-objects.js b/3-extra/2-array-of-objects.js index b028ab7f..2f22bfe9 100644 --- a/3-extra/2-array-of-objects.js +++ b/3-extra/2-array-of-objects.js @@ -22,7 +22,7 @@ function getHighestRatedInEachGenre(books) { } const highestRatedTitlesByGenre = Object.values(highestRatedBooks).map(book => book.title); - return highestRatedTitlesByGenre; + console.log(highestRatedTitlesByGenre) ; } From b8f50c5fa1dc3da67268a64ad1604ea7e84baf07 Mon Sep 17 00:00:00 2001 From: Mpanasetckiy Date: Mon, 6 Mar 2023 15:24:50 +0000 Subject: [PATCH 8/8] fix error --- 3-extra/2-array-of-objects.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/3-extra/2-array-of-objects.js b/3-extra/2-array-of-objects.js index 2f22bfe9..b028ab7f 100644 --- a/3-extra/2-array-of-objects.js +++ b/3-extra/2-array-of-objects.js @@ -22,7 +22,7 @@ function getHighestRatedInEachGenre(books) { } const highestRatedTitlesByGenre = Object.values(highestRatedBooks).map(book => book.title); - console.log(highestRatedTitlesByGenre) ; + return highestRatedTitlesByGenre; }