From 11dd6c3af908572f92a2049aedd3709dc92e2f09 Mon Sep 17 00:00:00 2001 From: nasir ali Date: Sun, 26 Feb 2023 15:18:15 +0000 Subject: [PATCH 1/8] started working on --- 2-mandatory/1-weather-report.js | 63 +++++++++++++++------------------ 1 file changed, 28 insertions(+), 35 deletions(-) diff --git a/2-mandatory/1-weather-report.js b/2-mandatory/1-weather-report.js index dcc2bdb0..1f785e69 100644 --- a/2-mandatory/1-weather-report.js +++ b/2-mandatory/1-weather-report.js @@ -12,52 +12,45 @@ */ function getTemperatureReport(cities) { - // TODO + // TODO } - +// /* ======= TESTS - DO NOT MODIFY ===== */ function temperatureService(city) { - let temparatureMap = new Map(); - - temparatureMap.set('London', 10); - temparatureMap.set('Paris', 12); - temparatureMap.set('Barcelona', 17); - temparatureMap.set('Dubai', 27); - temparatureMap.set('Mumbai', 29); - temparatureMap.set('São Paulo', 23); - temparatureMap.set('Lagos', 33); - - return temparatureMap.get(city); + let temparatureMap = new Map(); + + temparatureMap.set("London", 10); + temparatureMap.set("Paris", 12); + temparatureMap.set("Barcelona", 17); + temparatureMap.set("Dubai", 27); + temparatureMap.set("Mumbai", 29); + temparatureMap.set("São Paulo", 23); + temparatureMap.set("Lagos", 33); + + return temparatureMap.get(city); } test("should return a temperature report for the user's cities", () => { - let usersCities = [ - "London", - "Paris", - "São Paulo" - ] - - expect(getTemperatureReport(usersCities)).toEqual([ - "The temperature in London is 10 degrees", - "The temperature in Paris is 12 degrees", - "The temperature in São Paulo is 23 degrees" - ]); + let usersCities = ["London", "Paris", "São Paulo"]; + + expect(getTemperatureReport(usersCities)).toEqual([ + "The temperature in London is 10 degrees", + "The temperature in Paris is 12 degrees", + "The temperature in São Paulo is 23 degrees", + ]); }); test("should return a temperature report for the user's cities (alternate input)", () => { - let usersCities = [ - "Barcelona", - "Dubai" - ] - - expect(getTemperatureReport(usersCities)).toEqual([ - "The temperature in Barcelona is 17 degrees", - "The temperature in Dubai is 27 degrees" - ]); + let usersCities = ["Barcelona", "Dubai"]; + + expect(getTemperatureReport(usersCities)).toEqual([ + "The temperature in Barcelona is 17 degrees", + "The temperature in Dubai is 27 degrees", + ]); }); test("should return an empty array if the user hasn't selected any cities", () => { - expect(getTemperatureReport([])).toEqual([]); -}); \ No newline at end of file + expect(getTemperatureReport([])).toEqual([]); +}); From 98e24cf2afabc3e4912f6269176c5dd1d7150c4d Mon Sep 17 00:00:00 2001 From: nasir ali Date: Sun, 26 Feb 2023 17:08:50 +0000 Subject: [PATCH 2/8] fixed all the excersises --- 1-exercises/A-undefined/exercise.js | 17 +++++++---- 1-exercises/B-array-literals/exercise.js | 4 +-- 1-exercises/C-array-get-set/exercise.js | 5 ++-- 1-exercises/C-array-get-set/exercises2.js | 2 ++ 1-exercises/D-for-loop/exercise.js | 24 +++++++-------- .../E-while-loop-with-array/exercise.js | 30 ++++++++++++------- 6 files changed, 48 insertions(+), 34 deletions(-) diff --git a/1-exercises/A-undefined/exercise.js b/1-exercises/A-undefined/exercise.js index 0acfc78d..c74f76ba 100644 --- a/1-exercises/A-undefined/exercise.js +++ b/1-exercises/A-undefined/exercise.js @@ -12,25 +12,30 @@ // Example 1 let a; console.log(a); - +// Answer +// - a have not been assign a value but its being printed to the terminal. The computer dont khow what to do so it prints out the statement of undefined // Example 2 function sayHello() { - let message = "Hello"; + let message = "Hello"; } let hello = sayHello(); console.log(hello); - +// Answer +// - functino is being called to siign a value to var hello but theres no return to return the value // Example 3 function sayHelloToUser(user) { - console.log(`Hello ${user}`); + console.log(`Hello ${user}`); } sayHelloToUser(); - +// Answer +// - the value user have no value assgined // Example 4 -let arr = [1,2,3]; +let arr = [1, 2, 3]; console.log(arr[3]); +// Answer +// - the array a dont have vale at address 3. it only have 0 till 2 addresses. diff --git a/1-exercises/B-array-literals/exercise.js b/1-exercises/B-array-literals/exercise.js index 51eba5cc..e0fceb6e 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, 3, 2, 5, 6, 46, 34, 2345, 23459]; // add numbers from 1 to 10 into this array +let mentors = ["Daniel", "Khan", "dani"]; // 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..ed9da117 100644 --- a/1-exercises/C-array-get-set/exercise.js +++ b/1-exercises/C-array-get-set/exercise.js @@ -5,11 +5,12 @@ */ function first(arr) { - return; // complete this statement + return arr[0]; // complete this statement } function last(arr) { - return; // complete this statement + var a = arr.length; + 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..7e0ff023 100644 --- a/1-exercises/C-array-get-set/exercises2.js +++ b/1-exercises/C-array-get-set/exercises2.js @@ -7,6 +7,8 @@ */ let numbers = [1, 2, 3]; // Don't change this array literal declaration +numbers[2] = 4; +numbers[1] = 1; /* 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..e87fae3a 100644 --- a/1-exercises/D-for-loop/exercise.js +++ b/1-exercises/D-for-loop/exercise.js @@ -11,23 +11,19 @@ */ const WRITERS = [ - "Virginia Woolf", - "Zadie Smith", - "Jane Austen", - "Bell Hooks", - "Yukiko Motoya" -] - -const AGES = [ - 59, - 40, - 41, - 63, - 49 + "Virginia Woolf", + "Zadie Smith", + "Jane Austen", + "Bell Hooks", + "Yukiko Motoya", ]; -// TODO - Write for loop code here +const AGES = [59, 40, 41, 63, 49]; +// TODO - Write for loop code here +for (var i = 0; i < WRITERS.length; i++) { + console.log(`${WRITERS[i]} age is ${AGES[i]} \n`); +} /* The output should look something like this: diff --git a/1-exercises/E-while-loop-with-array/exercise.js b/1-exercises/E-while-loop-with-array/exercise.js index d584cd75..b2746318 100644 --- a/1-exercises/E-while-loop-with-array/exercise.js +++ b/1-exercises/E-while-loop-with-array/exercise.js @@ -5,19 +5,29 @@ */ const BIRTHDAYS = [ - "January 7th", - "February 12th", - "April 3rd", - "April 5th", - "May 3rd", - "July 11th", - "July 17th", - "September 28th", - "November 15th" + "January 7th", + "February 12th", + "April 3rd", + "April 5th", + "May 3rd", + "July 11th", + "July 17th", + "September 28th", + "November 15th", ]; function findFirstJulyBDay(birthdays) { - // TODO + // TODO + + var hold = []; + for (var i = 0; i < BIRTHDAYS.length; i++) { + var month = BIRTHDAYS[i]; + if (month.includes("July")) { + hold.push(month); + } + // console.log(BIRTHDAYS[i]); + } + return hold; } console.log(findFirstJulyBDay(BIRTHDAYS)); // should output "July 11th" From 5461201c5857e00d0cce5fc6b42c9779ec0bfeec Mon Sep 17 00:00:00 2001 From: nasir ali Date: Sun, 26 Feb 2023 17:25:27 +0000 Subject: [PATCH 3/8] fixed mandatory 1 --- 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 1f785e69..1b962ad2 100644 --- a/2-mandatory/1-weather-report.js +++ b/2-mandatory/1-weather-report.js @@ -13,6 +13,12 @@ function getTemperatureReport(cities) { // TODO + var temp_array = []; + for (var i = 0; i < cities.length; i++) { + var temp = temperatureService(cities[i]); + temp_array.push(`The temperature in ${cities[i]} is ${temp} degrees`); + } + return temp_array; } // From c0776ceee0947ce47a7104cd5e7cb564a2e4cf91 Mon Sep 17 00:00:00 2001 From: nasir ali Date: Sun, 26 Feb 2023 17:50:02 +0000 Subject: [PATCH 4/8] fixed mandatory --- 2-mandatory/2-financial-times.js | 79 +++++++++++++++++++------------ 2-mandatory/3-stocks.js | 81 ++++++++++++++++++++++---------- 2 files changed, 107 insertions(+), 53 deletions(-) diff --git a/2-mandatory/2-financial-times.js b/2-mandatory/2-financial-times.js index 2ce6fb73..610c2f61 100644 --- a/2-mandatory/2-financial-times.js +++ b/2-mandatory/2-financial-times.js @@ -5,7 +5,8 @@ Implement the function below, which will return a new array containing only article titles which will fit. */ function potentialHeadlines(allArticleTitles) { - // TODO + // TODO + return allArticleTitles.filter((title) => title.length < 65); } /* @@ -14,7 +15,15 @@ function potentialHeadlines(allArticleTitles) { (you can assume words will always be seperated by a space) */ function titleWithFewestWords(allArticleTitles) { - // TODO + // TODO + let shortestTitle = allArticleTitles[0]; + for (let i = 1; i < allArticleTitles.length; i++) { + const currentTitle = allArticleTitles[i]; + if (currentTitle.length < shortestTitle.length) { + shortestTitle = currentTitle; + } + } + return shortestTitle; } /* @@ -23,7 +32,9 @@ function titleWithFewestWords(allArticleTitles) { (Hint: remember that you can also loop through the characters of a string if you need to) */ function headlinesWithNumbers(allArticleTitles) { - // TODO + // TODO + + return allArticleTitles.filter((title) => /\d/.test(title)); } /* @@ -31,51 +42,61 @@ function headlinesWithNumbers(allArticleTitles) { Implement the function below to return this number - rounded to the nearest integer. */ function averageNumberOfCharacters(allArticleTitles) { - // TODO + // TODO + const totalCharacters = allArticleTitles.reduce( + (acc, title) => acc + title.length, + 0 + ); + const average = totalCharacters / allArticleTitles.length; + return Math.round(average); } - - /* ======= List of Articles - DO NOT MODIFY ===== */ const ARTICLE_TITLES = [ - "Streaming wars drive media groups to spend more than $100bn on new content", - "Amazon Prime Video India country head: streaming is driving a TV revolution", - "Aerospace chiefs prepare for bumpy ride in recovery of long-haul flights", - "British companies look to muscle in on US retail investing boom", - "Libor to take firm step towards oblivion on New Year's Day", - "Audit profession unattractive to new recruits, says PwC boss", - "Chinese social media users blast Elon Musk over near miss in space", - "Companies raise over $12tn in 'blockbuster' year for global capital markets", - "The three questions that dominate investment", - "Brussels urges Chile's incoming president to endorse EU trade deal", + "Streaming wars drive media groups to spend more than $100bn on new content", + "Amazon Prime Video India country head: streaming is driving a TV revolution", + "Aerospace chiefs prepare for bumpy ride in recovery of long-haul flights", + "British companies look to muscle in on US retail investing boom", + "Libor to take firm step towards oblivion on New Year's Day", + "Audit profession unattractive to new recruits, says PwC boss", + "Chinese social media users blast Elon Musk over near miss in space", + "Companies raise over $12tn in 'blockbuster' year for global capital markets", + "The three questions that dominate investment", + "Brussels urges Chile's incoming president to endorse EU trade deal", ]; /* ======= TESTS - DO NOT MODIFY ===== */ test("should only return potential headlines", () => { - expect(new Set(potentialHeadlines(ARTICLE_TITLES))).toEqual(new Set([ - "British companies look to muscle in on US retail investing boom", - "Libor to take firm step towards oblivion on New Year's Day", - "Audit profession unattractive to new recruits, says PwC boss", - "The three questions that dominate investment" - ])); + expect(new Set(potentialHeadlines(ARTICLE_TITLES))).toEqual( + new Set([ + "British companies look to muscle in on US retail investing boom", + "Libor to take firm step towards oblivion on New Year's Day", + "Audit profession unattractive to new recruits, says PwC boss", + "The three questions that dominate investment", + ]) + ); }); test("should return an empty array for empty input", () => { - expect(potentialHeadlines([])).toEqual([]); + expect(potentialHeadlines([])).toEqual([]); }); test("should return the title with the fewest words", () => { - expect(titleWithFewestWords(ARTICLE_TITLES)).toEqual("The three questions that dominate investment"); + expect(titleWithFewestWords(ARTICLE_TITLES)).toEqual( + "The three questions that dominate investment" + ); }); test("should only return headlines containing numbers", () => { - expect(new Set(headlinesWithNumbers(ARTICLE_TITLES))).toEqual(new Set([ - "Streaming wars drive media groups to spend more than $100bn on new content", - "Companies raise over $12tn in 'blockbuster' year for global capital markets" - ])); + expect(new Set(headlinesWithNumbers(ARTICLE_TITLES))).toEqual( + new Set([ + "Streaming wars drive media groups to spend more than $100bn on new content", + "Companies raise over $12tn in 'blockbuster' year for global capital markets", + ]) + ); }); test("should return the average number of characters in a headline", () => { - expect(averageNumberOfCharacters(ARTICLE_TITLES)).toEqual(65); + expect(averageNumberOfCharacters(ARTICLE_TITLES)).toEqual(65); }); diff --git a/2-mandatory/3-stocks.js b/2-mandatory/3-stocks.js index 72d62f94..e61b22c0 100644 --- a/2-mandatory/3-stocks.js +++ b/2-mandatory/3-stocks.js @@ -11,11 +11,11 @@ const STOCKS = ["aapl", "msft", "amzn", "googl", "tsla"]; const CLOSING_PRICES_LAST_5_DAYS_FOR_ALL_STOCKS = [ - [179.19, 180.33, 176.28, 175.64, 172.99], // AAPL - [340.69, 342.45, 334.69, 333.20, 327.29], // MSFT - [3384.44, 3393.39, 3421.37, 3420.74, 3408.34], // AMZN - [2951.88, 2958.13, 2938.33, 2928.30, 2869.45], // GOOGL - [1101.30, 1093.94, 1067.00, 1008.87, 938.53] // TSLA + [179.19, 180.33, 176.28, 175.64, 172.99], // AAPL + [340.69, 342.45, 334.69, 333.2, 327.29], // MSFT + [3384.44, 3393.39, 3421.37, 3420.74, 3408.34], // AMZN + [2951.88, 2958.13, 2938.33, 2928.3, 2869.45], // GOOGL + [1101.3, 1093.94, 1067.0, 1008.87, 938.53], // TSLA ]; /* @@ -34,7 +34,15 @@ const CLOSING_PRICES_LAST_5_DAYS_FOR_ALL_STOCKS = [ Functions can help with this! */ function getAveragePrices(closingPricesForAllStocks) { - // TODO + // TODO + const averages = []; + for (let i = 0; i < closingPricesForAllStocks.length; i++) { + const stockPrices = closingPricesForAllStocks[i]; + const total = stockPrices.reduce((acc, price) => acc + price, 0); + const average = total / stockPrices.length; + averages.push(parseFloat(average.toFixed(2))); + } + return averages; } /* @@ -48,7 +56,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 + // TODO + const priceChanges = []; + + for (let i = 0; i < closingPricesForAllStocks.length; i++) { + const firstPrice = closingPricesForAllStocks[i][0]; + const lastPrice = + closingPricesForAllStocks[i][closingPricesForAllStocks[i].length - 1]; + const change = lastPrice - firstPrice; + + priceChanges.push(parseFloat(change.toFixed(2))); + } + + return priceChanges; } /* @@ -64,31 +84,44 @@ function getPriceChanges(closingPricesForAllStocks) { The price should be shown with exactly 2 decimal places. */ function highestPriceDescriptions(closingPricesForAllStocks, stocks) { - // TODO -} + // TODO + const result = []; + + for (let i = 0; i < stocks.length; i++) { + const stock = stocks[i]; + const prices = closingPricesForAllStocks[i]; + const highestPrice = Math.max(...prices); + const formattedPrice = highestPrice.toFixed(2); + const capitalizedStock = stock.toUpperCase(); + result.push( + `The highest price of ${capitalizedStock} in the last 5 days was ${formattedPrice}` + ); + } + return result; +} /* ======= TESTS - DO NOT MODIFY ===== */ test("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] - ); + expect(getAveragePrices(CLOSING_PRICES_LAST_5_DAYS_FOR_ALL_STOCKS)).toEqual([ + 176.89, 335.66, 3405.66, 2929.22, 1041.93, + ]); }); test("should return the price change for each stock", () => { - expect(getPriceChanges(CLOSING_PRICES_LAST_5_DAYS_FOR_ALL_STOCKS)).toEqual( - [-6.2, -13.4, 23.9, -82.43, -162.77] - ); + expect(getPriceChanges(CLOSING_PRICES_LAST_5_DAYS_FOR_ALL_STOCKS)).toEqual([ + -6.2, -13.4, 23.9, -82.43, -162.77, + ]); }); test("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", - "The highest price of MSFT in the last 5 days was 342.45", - "The highest price of AMZN in the last 5 days was 3421.37", - "The highest price of GOOGL in the last 5 days was 2958.13", - "The highest price of TSLA in the last 5 days was 1101.30" - ] - ); + 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", + "The highest price of MSFT in the last 5 days was 342.45", + "The highest price of AMZN in the last 5 days was 3421.37", + "The highest price of GOOGL in the last 5 days was 2958.13", + "The highest price of TSLA in the last 5 days was 1101.30", + ]); }); From baeb9a5356977ef54915d6f63d2674831cd9020c Mon Sep 17 00:00:00 2001 From: nasir ali Date: Sun, 26 Feb 2023 19:38:39 +0000 Subject: [PATCH 5/8] extra 1 tests dont run --- 3-extra/1-radio-stations.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/3-extra/1-radio-stations.js b/3-extra/1-radio-stations.js index 577076e9..be8727cd 100644 --- a/3-extra/1-radio-stations.js +++ b/3-extra/1-radio-stations.js @@ -14,6 +14,13 @@ */ // `getAllFrequencies` goes here +function getAllFrequencies() { + const frequencies = []; + for (let i = 87; i <= 108; i++) { + frequencies.push(i); + } + return frequencies; +} /** * Next, let's write a function that gives us only the frequencies that are radio stations. @@ -26,6 +33,12 @@ */ // `getStations` goes here +function getStations() { + const frequencies = getAllFrequencies(); + const stations = frequencies.filter((frequency) => isRadioStation(frequency)); + return stations; +} + /* * ======= TESTS - DO NOT MODIFY ======= * Note: You are not expected to understand everything below this comment! @@ -65,3 +78,6 @@ test("getAllFrequencies() returns all frequencies between 87 and 108", () => { test("getStations() returns all the available stations", () => { expect(getStations()).toEqual(getAvailableStations()); }); +// console.log(getAllFrequencies()); + +// console.log(getStations()); From f9759e82fc2aa1f4f30d069d7477cc9e7894615d Mon Sep 17 00:00:00 2001 From: nasir ali Date: Mon, 27 Feb 2023 12:40:01 +0000 Subject: [PATCH 6/8] solved the extra but stuck with test errors --- 3-extra/2-array-of-objects.js | 131 ++++++++++++++++++---------------- 3-extra/3-fibonacci.js | 25 ++++--- 3-extra/test.js | 9 +++ 3 files changed, 92 insertions(+), 73 deletions(-) create mode 100644 3-extra/test.js diff --git a/3-extra/2-array-of-objects.js b/3-extra/2-array-of-objects.js index ee57960f..c921966f 100644 --- a/3-extra/2-array-of-objects.js +++ b/3-extra/2-array-of-objects.js @@ -11,72 +11,79 @@ */ function getHighestRatedInEachGenre(books) { - // TODO -} + // TODO + const highestRated = books.reduce((result, book) => { + if (book.rating > (result[book.genre]?.rating || 0)) { + result[book.genre] = book; + } + return result; + }, {}); + return Object.values(highestRated).map((book) => book.title); +} /* ======= Book data - DO NOT MODIFY ===== */ const BOOKS = [ - { - title: "The Lion, the Witch and the Wardrobe", - genre: "children", - rating: 4.7 - }, - { - title: "Sapiens: A Brief History of Humankind", - genre: "non-fiction", - rating: 4.7 - }, - { - title: "Nadiya's Fast Flavours", - genre: "cooking", - rating: 4.7 - }, - { - title: "Harry Potter and the Philosopher's Stone", - genre: "children", - rating: 4.8 - }, - { - title: "A Life on Our Planet", - genre: "non-fiction", - rating: 4.8 - }, - { - title: "Dishoom: The first ever cookbook from the much-loved Indian restaurant", - genre: "cooking", - rating: 4.85 - }, - { - title: "Gangsta Granny Strikes Again!", - genre: "children", - rating: 4.9 - }, - { - title: "Diary of a Wimpy Kid", - genre: "children", - rating: 4.6 - }, - { - title: "BOSH!: Simple recipes. Unbelievable results. All plants.", - genre: "cooking", - rating: 4.6 - }, - { - title: "The Book Your Dog Wishes You Would Read", - genre: "non-fiction", - rating: 4.85 - }, -] - + { + title: "The Lion, the Witch and the Wardrobe", + genre: "children", + rating: 4.7, + }, + { + title: "Sapiens: A Brief History of Humankind", + genre: "non-fiction", + rating: 4.7, + }, + { + title: "Nadiya's Fast Flavours", + genre: "cooking", + rating: 4.7, + }, + { + title: "Harry Potter and the Philosopher's Stone", + genre: "children", + rating: 4.8, + }, + { + title: "A Life on Our Planet", + genre: "non-fiction", + rating: 4.8, + }, + { + title: + "Dishoom: The first ever cookbook from the much-loved Indian restaurant", + genre: "cooking", + rating: 4.85, + }, + { + title: "Gangsta Granny Strikes Again!", + genre: "children", + rating: 4.9, + }, + { + title: "Diary of a Wimpy Kid", + genre: "children", + rating: 4.6, + }, + { + title: "BOSH!: Simple recipes. Unbelievable results. All plants.", + genre: "cooking", + rating: 4.6, + }, + { + title: "The Book Your Dog Wishes You Would Read", + genre: "non-fiction", + rating: 4.85, + }, +]; /* ======= TESTS - DO NOT MODIFY ===== */ test("should return the highest rated book in each genre", () => { - expect(new Set(getHighestRatedInEachGenre(BOOKS))).toEqual(new Set( - [ - "The Book Your Dog Wishes You Would Read", - "Gangsta Granny Strikes Again!", - "Dishoom: The first ever cookbook from the much-loved Indian restaurant" - ] - )); -}); \ No newline at end of file + expect(new Set(getHighestRatedInEachGenre(BOOKS))).toEqual( + new Set([ + "The Book Your Dog Wishes You Would Read", + "Gangsta Granny Strikes Again!", + "Dishoom: The first ever cookbook from the much-loved Indian restaurant", + ]) + ); +}); diff --git a/3-extra/3-fibonacci.js b/3-extra/3-fibonacci.js index 9ef9aec7..ea4b4b08 100644 --- a/3-extra/3-fibonacci.js +++ b/3-extra/3-fibonacci.js @@ -14,24 +14,27 @@ */ function generateFibonacciSequence(n) { - // TODO + // TODO + let fib = []; + for (var i = 0; i < n; i++) { + fib.push(i); + } + return fib; } /* ======= TESTS - DO NOT MODIFY ===== */ test("should return the first 10 numbers in the Fibonacci Sequence", () => { - expect(generateFibonacciSequence(10)).toEqual( - [0, 1, 1, 2, 3, 5, 8, 13, 21, 34] - ); + expect(generateFibonacciSequence(10)).toEqual([ + 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, + ]); }); test("should return the first 5 numbers in the Fibonacci Sequence", () => { - expect(generateFibonacciSequence(5)).toEqual( - [0, 1, 1, 2, 3] - ); + expect(generateFibonacciSequence(5)).toEqual([0, 1, 1, 2, 3]); }); test("should return the first 15 numbers in the Fibonacci Sequence", () => { - expect(generateFibonacciSequence(15)).toEqual( - [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377] - ); -}); \ No newline at end of file + expect(generateFibonacciSequence(15)).toEqual([ + 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, + ]); +}); diff --git a/3-extra/test.js b/3-extra/test.js new file mode 100644 index 00000000..434b3a71 --- /dev/null +++ b/3-extra/test.js @@ -0,0 +1,9 @@ +function generateFibonacciSequence(n) { + // TODO + let fib = []; + for (var i = 0; i < n; i++) { + fib.push(i); + } + return fib; +} +console.log(generateFibonacciSequence(90)); From 52d88dfaaed6bf64abf8f94c9dc61c65f7548c36 Mon Sep 17 00:00:00 2001 From: nasir ali Date: Wed, 1 Mar 2023 17:50:17 +0000 Subject: [PATCH 7/8] fixed extra with help of Zsolt --- 3-extra/3-fibonacci.js | 8 +++++--- 3-extra/test.js | 11 +++++++---- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/3-extra/3-fibonacci.js b/3-extra/3-fibonacci.js index ea4b4b08..cc7a7634 100644 --- a/3-extra/3-fibonacci.js +++ b/3-extra/3-fibonacci.js @@ -15,9 +15,11 @@ function generateFibonacciSequence(n) { // TODO - let fib = []; - for (var i = 0; i < n; i++) { - fib.push(i); + let fib = [0, 1]; + var sum = 0; + for (var i = 1; i < n - 1; i++) { + sum = fib[i - 1] + fib[i]; + fib.push(sum); } return fib; } diff --git a/3-extra/test.js b/3-extra/test.js index 434b3a71..0ccc8f4f 100644 --- a/3-extra/test.js +++ b/3-extra/test.js @@ -1,9 +1,12 @@ function generateFibonacciSequence(n) { // TODO - let fib = []; - for (var i = 0; i < n; i++) { - fib.push(i); + let fib = [0, 1]; + var sum = 0; + for (var i = 1; i < n; i++) { + sum = fib[i - 1] + fib[i]; + fib.push(sum); } return fib; } -console.log(generateFibonacciSequence(90)); + +console.log(generateFibonacciSequence(10)); From 79ff11b8cb2b355d0864f1ad1331d0c12adbf194 Mon Sep 17 00:00:00 2001 From: nasir ali Date: Wed, 8 Mar 2023 21:37:37 +0000 Subject: [PATCH 8/8] fixed the variable names with let --- 2-mandatory/1-weather-report.js | 11 ++++------- 3-extra/3-fibonacci.js | 12 ++++-------- 3-extra/test.js | 12 ------------ 3 files changed, 8 insertions(+), 27 deletions(-) delete mode 100644 3-extra/test.js diff --git a/2-mandatory/1-weather-report.js b/2-mandatory/1-weather-report.js index 1b962ad2..2cecb548 100644 --- a/2-mandatory/1-weather-report.js +++ b/2-mandatory/1-weather-report.js @@ -13,9 +13,9 @@ function getTemperatureReport(cities) { // TODO - var temp_array = []; - for (var i = 0; i < cities.length; i++) { - var temp = temperatureService(cities[i]); + const temp_array = []; + for (let i = 0; i < cities.length; i++) { + let temp = temperatureService(cities[i]); temp_array.push(`The temperature in ${cities[i]} is ${temp} degrees`); } return temp_array; @@ -51,10 +51,7 @@ test("should return a temperature report for the user's cities", () => { test("should return a temperature report for the user's cities (alternate input)", () => { let usersCities = ["Barcelona", "Dubai"]; - expect(getTemperatureReport(usersCities)).toEqual([ - "The temperature in Barcelona is 17 degrees", - "The temperature in Dubai is 27 degrees", - ]); + expect(getTemperatureReport(usersCities)).toEqual(["The temperature in Barcelona is 17 degrees", "The temperature in Dubai is 27 degrees"]); }); test("should return an empty array if the user hasn't selected any cities", () => { diff --git a/3-extra/3-fibonacci.js b/3-extra/3-fibonacci.js index cc7a7634..a67cde55 100644 --- a/3-extra/3-fibonacci.js +++ b/3-extra/3-fibonacci.js @@ -16,8 +16,8 @@ function generateFibonacciSequence(n) { // TODO let fib = [0, 1]; - var sum = 0; - for (var i = 1; i < n - 1; i++) { + let sum = 0; + for (let i = 1; i < n - 1; i++) { sum = fib[i - 1] + fib[i]; fib.push(sum); } @@ -26,9 +26,7 @@ function generateFibonacciSequence(n) { /* ======= TESTS - DO NOT MODIFY ===== */ test("should return the first 10 numbers in the Fibonacci Sequence", () => { - expect(generateFibonacciSequence(10)).toEqual([ - 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, - ]); + expect(generateFibonacciSequence(10)).toEqual([0, 1, 1, 2, 3, 5, 8, 13, 21, 34]); }); test("should return the first 5 numbers in the Fibonacci Sequence", () => { @@ -36,7 +34,5 @@ test("should return the first 5 numbers in the Fibonacci Sequence", () => { }); test("should return the first 15 numbers in the Fibonacci Sequence", () => { - expect(generateFibonacciSequence(15)).toEqual([ - 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, - ]); + expect(generateFibonacciSequence(15)).toEqual([0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377]); }); diff --git a/3-extra/test.js b/3-extra/test.js deleted file mode 100644 index 0ccc8f4f..00000000 --- a/3-extra/test.js +++ /dev/null @@ -1,12 +0,0 @@ -function generateFibonacciSequence(n) { - // TODO - let fib = [0, 1]; - var sum = 0; - for (var i = 1; i < n; i++) { - sum = fib[i - 1] + fib[i]; - fib.push(sum); - } - return fib; -} - -console.log(generateFibonacciSequence(10));