Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function createSortedList() {
- const list = {
- numbers: [],
- get size(){
- return this.numbers.length;
- },
- add: function(element) {
- this.numbers.push(element);
- this.numbers.sort((a, b) => a - b);
- },
- remove: function(index){
- if (index >= 0 && index < this.numbers.length) {
- this.numbers.splice(index, 1);
- this.numbers.sort((a, b) => a - b);
- }
- },
- get: function(index) {
- if (index >= 0 && index < this.numbers.length) {
- return this.numbers[index];
- }
- },
- };
- return list;
- }
- let list = createSortedList();
- list.add(5);
- list.add(6);
- list.add(7);
- console.log(list.get(1));
- list.remove(1);
- console.log(list.get(1));
- console.log(list.size)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement