Skip to content
Open

done #2487

Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 39 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,48 @@
class SortedList {
constructor() {}
constructor() {
this.length = 0;
this.items = [];
}

add(item) {}
add(item) {
this.length++;
this.items.push(item);
this.items.sort((a,b) => a - b);
}

get(pos) {}
get(pos) {
if(pos < 0 || pos >= this.length ){
throw new Error("OutOfBounds");
}
return this.items[pos];
}

max() {}
max() {
if( this.items >= 0 ){
throw new Error("EmptySortedList");
}
return this.items [this.length - 1];
}

min() {}
min() {
if( this.items >= 0 ){
return new Exception("EmptySortedList");
}
return this.items [0];
}

sum() {}
sum() {
if (this.length === 0) {
return 0;
}

let total = 0;
for (let i = 0; i < this.length; i++) {
total += this.items[i];
}

return total;
}

avg() {}
}
Expand Down