├── style.css ├── script.js └── index.html /style.css: -------------------------------------------------------------------------------- 1 | *{ 2 | margin: 0; 3 | padding: 0; 4 | } 5 | h1{ 6 | color: red; 7 | font-size: 40px; 8 | text-align: center; 9 | text-decoration: underline red; 10 | margin-top: 20px; 11 | } 12 | hr{ 13 | width: 100%; 14 | height: 3px; 15 | background-color: grey; 16 | margin: 20px 0; 17 | } 18 | .mainContainer{ 19 | margin: 0 60px; 20 | } 21 | .bold{ 22 | font-size: 15px; 23 | font-weight: 700; 24 | } 25 | .blue{ 26 | color: blue; 27 | } -------------------------------------------------------------------------------- /script.js: -------------------------------------------------------------------------------- 1 | // Map and set handson 2 | 3 | // Q1 4 | var a = "abcbbssd" 5 | 6 | let b = new Set(a) 7 | console.log(b) 8 | b=[...b].join("") 9 | console.log(b) 10 | 11 | // using normal function 12 | function countAplhabtes(str){ 13 | const aphabletCount = {} 14 | 15 | for(let char of str){ 16 | if( char in aphabletCount){ 17 | aphabletCount[char]++ 18 | } 19 | else{ 20 | aphabletCount[char] = 1 21 | } 22 | } 23 | for(let char in aphabletCount){ 24 | console.log(`${char} = ${aphabletCount[char]}}`) 25 | } 26 | } 27 | 28 | countAplhabtes("asdfgygfhad") 29 | 30 | 31 | // Using Map() 32 | function countAplhabtes(str){ 33 | const aphabletCount = new Map() 34 | 35 | for(let char of str){ 36 | if(aphabletCount.has(char)){ 37 | aphabletCount.set(char, aphabletCount.get(char)+1) 38 | } 39 | else{ 40 | aphabletCount.set(char, 1) 41 | } 42 | } 43 | for(let [char,count] of aphabletCount){ 44 | console.log(`${char} = ${count}}`) 45 | } 46 | } 47 | 48 | countAplhabtes("asdfgygfhad") 49 | 50 | 51 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Map and Sets 7 | 8 | 9 | 10 | 11 | 12 |

Maps And Sets

13 |
14 |
15 |
16 |

Q1 :- Problem:- 17 | You are given a string (STR) of length N, consisting of only the lower case English alphabet. 18 | Your task is to remove all the duplicate occurrences of characters in the string. 19 |
20 |
21 | Input : abcadeecfb
22 |
23 | Output : abcdef" 24 |

25 |

ANS :-

26 |
27 |                 var a = "abcbbssd"
28 |                 let b = new Set(a)
29 |                 b=[...b].join("")
30 |                 console.log(b)
31 |             
32 |

OUTPUT :- abcdef

33 |
34 |
35 |
36 |

Q2 :- Problem :- You are given a string (STR) of length N, you have to print the count of all alphabet.(using maps) 37 |
38 | Input:- abcadeecfb

39 | 40 | Output:
41 | a=2
42 | b=2
43 | c=2
44 | d=1
45 | e=2
46 | f=1
47 |

48 |

ANS :-

49 |
50 |                 function countAplhabtes(str){
51 |                     const aphabletCount = new Map()
52 |                     
53 |                     for(let char of str){
54 |                         if(aphabletCount.has(char)){
55 |                             aphabletCount.set(char, aphabletCount.get(char)+1)
56 |                         }
57 |                         else{
58 |                             aphabletCount.set(char, 1)
59 |                         }
60 |                     }
61 |                     for(let [char,count] of aphabletCount){
62 |                     console.log(`${char} = ${count}}`)
63 |                 } 
64 |                 }
65 |             
66 |

OUTPUT :- a=2
67 | b=2
68 | c=2
69 | d=1
70 | e=2
71 | f=1

72 |
73 |
74 |
75 | 76 | 77 | --------------------------------------------------------------------------------