From d11cf65a959cfddf77ccfecb7ad366b09ec7bcd1 Mon Sep 17 00:00:00 2001 From: Gideon-Buba Date: Wed, 30 Aug 2023 11:18:05 +0100 Subject: [PATCH] Completed day 10 --- .../10_day_starter/scripts/main.js | 77 ++++++++++++++++++- 1 file changed, 76 insertions(+), 1 deletion(-) diff --git a/10_Day_Sets_and_Maps/10_day_starter/scripts/main.js b/10_Day_Sets_and_Maps/10_day_starter/scripts/main.js index c6045c8..bf0e8e5 100644 --- a/10_Day_Sets_and_Maps/10_day_starter/scripts/main.js +++ b/10_Day_Sets_and_Maps/10_day_starter/scripts/main.js @@ -1,2 +1,77 @@ console.log(countries) -alert('Open the console and check if the countries has been loaded') \ No newline at end of file +//alert('Open the console and check if the countries has been loaded') + + +// Day 10 Exercises +const a = [4, 5, 8, 9] +const b = [3, 4, 5, 7] +const countries = ['Finland', 'Sweden', 'Norway'] + + +// Exercise 1 +const emptySet = new Set(); +console.log(emptySet); + +// Exercise 2 +const numberSet = new Set(); + +for(let i = 0; i < 10; i++) { + numberSet.add(i); +} + +console.log(numberSet) + +// Exercise 3 +setOfCountries = new Set(); +for(const country of countries){ + setOfCountries.add(country) +} + +console.log(setOfCountries.delete('Sweden')); + +// Exercise 4 +setOfCountries.clear() + +console.log(setOfCountries); + +// Exercise 5 +const setOfFiveStrings = new Set(); + +for(const country of countries) { + if(typeof country === 'string') { + setOfFiveStrings.add(country); + } +} + +console.log(setOfFiveStrings) + +// Exercise 6 +const countryCharacterCountMap = new Map(); + +for (const country of countries) { + countryCharacterCountMap.set(country, country.length); +} + +console.log(countryCharacterCountMap); + + // Exercise Level 2 +// Exercise 1 +let c = [...a, ...b]; + +let A = new Set(a); +let B = new Set(b); +let C = new Set(c); + +console.log(c) + +// Exercise 2 +let c = a.filter((num) => B.has(num)) +let C = new Set(c) + +console.log(c); + +// Exercise + + + +