-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-original.js
77 lines (61 loc) · 1.77 KB
/
test-original.js
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
66
67
68
69
70
71
72
73
74
75
76
77
// Task: Implement a 'Range Collection' class.
// A pair of integers define a range, for example: [1, 5). This range includes integers: 1, 2, 3, and 4.
// A range collection is an aggregate of these ranges: [1, 5), [10, 11), [100, 201)
/**
* RangeCollection class
* NOTE: Feel free to add any extra member variables/functions you like.
*/
class RangeCollection {
/**
* Adds a range to the collection
* @param {Array<number>} range - Array of two integers that specify beginning and end of range.
*/
add(range) {
// TODO: implement this
}
/**
* Removes a range from the collection
* @param {Array<number>} range - Array of two integers that specify beginning and end of range.
*/
remove(range) {
// TODO: implement this
}
/**
* Prints out the list of ranges in the range collection
*/
print() {
// TODO: implement this
}
}
// Example run
const rc = new RangeCollection();
rc.add([1, 5]);
rc.print();
// Should display: [1, 5)
rc.add([10, 20]);
rc.print();
// Should display: [1, 5) [10, 20)
rc.add([20, 20]);
rc.print();
// Should display: [1, 5) [10, 20)
rc.add([20, 21]);
rc.print();
// Should display: [1, 5) [10, 21)
rc.add([2, 4]);
rc.print();
// Should display: [1, 5) [10, 21)
rc.add([3, 8]);
rc.print();
// Should display: [1, 8) [10, 21)
rc.remove([10, 10]);
rc.print();
// Should display: [1, 8) [10, 21)
rc.remove([10, 11]);
rc.print();
// Should display: [1, 8) [11, 21)
rc.remove([15, 17]);
rc.print();
// Should display: [1, 8) [11, 15) [17, 21)
rc.remove([3, 19]);
rc.print();
// Should display: [1, 3) [19, 21)