Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class List {
- constructor(list = []) {
- this.list = list.sort((a, b) => a - b);
- this.size = this.list.length;
- }
- add(element) {
- this.list.push(element);
- this.list.sort((a, b) => a - b)
- this.size++
- return;
- }
- remove(index) {
- if (index <= this.size - 1 && index > 0) {
- this.list.splice(index, 1);
- this.size--;
- }
- return
- }
- get(index) {
- if (index <= this.size - 1 && index > 0) {
- return this.list[index];
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement