-
Notifications
You must be signed in to change notification settings - Fork 0
/
sets.html
46 lines (33 loc) · 1.24 KB
/
sets.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
<!DOCTYPE html>
<html>
<head>
<!-- Load babel 5 - babel-core -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.38/browser.js"></script>
<script type="text/babel">
var books = new Set();
books.add('Pride and Prejudice');
books.add('War and Peace')
.add('Oliver Twist');
console.log(books);
console.log('how many books?', books.size);
console.log('has Oliver Twist?', books.has('Oliver Twist'));
books.delete('Oliver Twist');
console.log('has Liver Twist?', books.has('Oliver Twist'));
// Value should be unique, will remove all duplicated items
var data = [4,2,4,2,4,2,4,2,4,2,4,2,4];
var set = new Set(data);
console.log("data length " + data.length);
console.log("set size " + set.size);
</script>
<title>Sets</title>
</head>
<body>
<h1>Hit the pit</h1>
<h2>Sets</h2>
<ul>
<li>Are collections of values</li>
<li>Can be any types</li>
<li>Each value must be unique, will remove all duplicated items</li>
</ul>
</body>
</html>