From f270fd65af2001d68e242f6ddfe78ca5dad08920 Mon Sep 17 00:00:00 2001 From: Jose Linardo Date: Sun, 26 Jun 2022 15:38:00 -0500 Subject: [PATCH] day 10 level 1 done --- .../10_day_starter/scripts/main.js | 43 ++++++++++++++++++- 1 file changed, 42 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..5f5eff7 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,43 @@ 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') + +//Exercises:Level 1 +/*const a = [4, 5, 8, 9] +const b = [3, 4, 5, 7] +const countries = ['Finland', 'Sweden', 'Norway']*/ + +//1.create an empty set +const set = new Set(); +//2.Create a set containing 0 to 10 using loop +const set1 = new Set(); +for (let i = 0; i < 10; i++) { + set.add(i); +} + +console.log(set); +//3. Remove an element from a set +const arr = [2, 8, 10, 7]; +const set2 = new Set(arr); +set.delete(10); + +console.log(set2); // Set(3) {2, 8, 7} +//4. Clear a set +const arr1 = ['a', 'b', 'c', 'd']; +const set3 = new Set(arr); +set.clear(); + +console.log(set3); +//5. Create a set of 5 string elements from array +const fruits = ['apple', 'mango', 'kiwi', 'peach', 'orange'] +const setOfFruits = new Set(fruits); + +console.log(setOfFruits); +//6. Create a map of countries and number of characters of a country +const countries = ['Finland', 'Sweden', 'Denmark', 'Norway', 'IceLand']; +const mapOfCountries = new Map(); + +for (const ctr of countries) { + mapOfCountries.set(ctr, ctr.length) +} + +console.log(mapOfCountries);