Guest User

Untitled

a guest
Oct 17th, 2019
104
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class List {
  2.     arr = [];
  3.  
  4.     add(element) {
  5.         this.arr.push(element)
  6.     }
  7.  
  8.     remove(index) {
  9.         if (this.arr.indexOf(index) !== -1) {
  10.             throw new Error(`Index doesn't exist`);
  11.        } else {
  12.            this.arr.splice(index, 1);
  13.        }
  14.    }
  15.  
  16.    get(index) {
  17.        if (this.arr.indexOf(index) !== -1) {
  18.            throw new Error(`Index doesn't exist`);
  19.         } else {
  20.             return this.arr[index];
  21.         }
  22.     }
  23.  
  24.     size() {
  25.         return this.arr.length;
  26.     }
  27. }
RAW Paste Data