Advertisement
HariNikolov

Untitled

Oct 20th, 2019
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class List {
  2.     constructor(list = []) {
  3.         this.list = list.sort((a, b) => a - b);
  4.         this.size = this.list.length;
  5.     }
  6.  
  7.     add(element) {
  8.         this.list.push(element);
  9.         this.list.sort((a, b) => a - b)
  10.         this.size++
  11.         return;
  12.     }
  13.  
  14.     remove(index) {
  15.         if (index <= this.size - 1 && index > 0) {
  16.             this.list.splice(index, 1);
  17.             this.size--;
  18.         }
  19.         return
  20.     }
  21.  
  22.     get(index) {
  23.         if (index <= this.size - 1 && index > 0) {
  24.             return this.list[index];
  25.         }
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement