-
Notifications
You must be signed in to change notification settings - Fork 0
/
index-9.html
65 lines (62 loc) · 1.77 KB
/
index-9.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="keywords" content="Operators & Expressions" />
<title>Coding Assisement</title>
<link rel="stylesheet" href="./style.css" />
</head>
<body>
<h2>9. maps & sets</h2>
<div class="Que">
<p>
Que.1 You are given a string (STR) of length N, consisting of only the
lower case English alphabet. Your task is to remove all the duplicate
occurrences of characters in the string. <br /><br />
<strong> Input: </strong> abcadeecfb <br />
<strong>Output:</strong> abcdef
</p>
<pre>
let Str = "abcadeecfb";
const S = new Set();
for (let i in Str) {
S.add(Str[i]);
}
console.log(...S); // a b c d e f
</pre
>
<p>
Que.2 You are given a string (STR) of length N, you have to print the
count of all alphabet.(using maps) <br /><br /><strong>Input:</strong
>abcadeecfb <br /><strong>Output:</strong> <br />
a=2 <br />
b=2 <br />
c=2 <br />
d=1 <br />
e=2 <br />
f=1
</p>
<pre>
let Words = "abcadeecfb";
let map = new Map();
for (let i in Words) {
if (map.has(Words[i])) {
map.set(Words[i], Number(map.get(Words[i])) + 1);
} else {
map.set(Words[i], 1);
}
}
for (const [key, value] of map) {
console.log(key + " = " + value);
}
</pre
>
</div>
<div class="container">
<div class="row"><a href="./index-8.html">Back</a></div>
<div class="row"><a href="./index-10.html">Next</a></div>
</div>
</body>
</html>