Guest User

Untitled

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