Advertisement
divanov94

Untitled

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