Advertisement
Todorov_Stanimir

06. Sorted List Exercise: Classes

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