Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class List {
- arr = [];
- constructor(add, remove, get, size) {
- this.add = function add(element) {
- this.arr.push(element)
- }
- this.remove = function remove(index) {
- if (this.arr.indexOf(index) !== -1) {
- throw new Error(`Index doesn't exist`);
- } else {
- this.arr.splice(index, 1);
- }
- }
- this.get = function get(index) {
- if (this.arr.indexOf(index) !== -1) {
- throw new Error(`Index doesn't exist`);
- } else {
- return this.arr[index];
- }
- }
- this.size = function size() {
- return this.arr.length;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement