From d64329bcdcf8a6ddfd761116ca9c333c1abcf3fa Mon Sep 17 00:00:00 2001 From: Shadi38 <113238379+Shadi38@users.noreply.github.com> Date: Thu, 9 Mar 2023 23:54:11 +0000 Subject: [PATCH] finishing all mandatory --- 2-mandatory/1-weather-report.js | 88 +++++++++++++++++++------------- 2-mandatory/2-financial-times.js | 67 ++++++++++++++++++++++-- 2-mandatory/3-stocks.js | 54 ++++++++++++++++++-- 3 files changed, 166 insertions(+), 43 deletions(-) diff --git a/2-mandatory/1-weather-report.js b/2-mandatory/1-weather-report.js index dcc2bdb0..3565ce4d 100644 --- a/2-mandatory/1-weather-report.js +++ b/2-mandatory/1-weather-report.js @@ -10,54 +10,72 @@ For example, "The temperature in London is 10 degrees" - Hint: you can call the temperatureService function from your function */ +const cities = [ + "London", + "Paris", + "Barselona", + "Dubai", + "Mumbai", + "São Paulo", + "Logos", +]; function getTemperatureReport(cities) { - // TODO -} + const citystrings = []; + + for (const item of cities) { + citystrings.push( + "The temperature in" + + " " + + item + + " " + + "is" + + " " + + temperatureService(item) + + " " + + "degrees" + ); + } + return citystrings; + } /* ======= 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([]); +}); + diff --git a/2-mandatory/2-financial-times.js b/2-mandatory/2-financial-times.js index 2ce6fb73..e7cb35b0 100644 --- a/2-mandatory/2-financial-times.js +++ b/2-mandatory/2-financial-times.js @@ -5,16 +5,43 @@ Implement the function below, which will return a new array containing only article titles which will fit. */ function potentialHeadlines(allArticleTitles) { - // TODO -} + const newarray = []; + + for (const item of allArticleTitles) { + if (item.length <= 65) { + newarray.push(item); + } + } + return newarray; + } + /* 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) */ + function titleWithFewestWords(allArticleTitles) { - // TODO + + let fewestWord=ARTICLE_TITLES[0].split(' ').length; + let finalTitle=ARTICLE_TITLES[0]; + let i=1; + + while(iFirstPrice){ + FirstPrice = price; + } + i=i+1; + } + + Name = stocks[num].toUpperCase(); + result.push(`The highest price of ${Name} in the last 5 days was ${FirstPrice.toFixed(2)}`); + num = num + 1; +} +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( @@ -92,3 +134,9 @@ test("should return a description of the highest price for each stock", () => { ] ); }); + + + + + +