Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class List {
- constructor() {
- this.collection = [];
- this.size = this.collection.length;
- }
- add(num) {
- this.collection.push(num);
- this.collection.sort((a, b) => a - b);
- this.size = this.collection.length;
- }
- remove(index) {
- if (this.collection.length - 1 >= index) {
- this.collection.splice(index, 1);
- this.size = this.collection.length;
- } else {
- throw Error('Index does not exist!');
- }
- }
- get(index) {
- if (this.collection.length - 1 >= index) {
- return this.collection[index];
- } else {
- throw Error('Index does not exist!');
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement