-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathseqSet.js
More file actions
35 lines (32 loc) · 729 Bytes
/
Copy pathseqSet.js
File metadata and controls
35 lines (32 loc) · 729 Bytes
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
function Set() {
this.dataStore = [];
this.add = add;
this.show = show;
}
function add(data) {
if (this.dataStore.indexOf(data) === -1) {
if (this.dataStore.length === 0) {
this.dataStore.push(data);
} else {
for (var i = 0; i < this.dataStore.length; i++) {
if (data >= this.dataStore[i]) {
this.dataStore.splice(i + 1, 0, data);
break;
}
}
}
return true;
} else {
return false;
}
}
function show() {
return this.dataStore;
}
// test
var names = new Set();
names.add('aaa');
names.add('ddd');
names.add('ccc');
names.add('bbb');
print(names.show());