diff --git a/index.js b/index.js index 0f4b28b4..da720c95 100644 --- a/index.js +++ b/index.js @@ -1,17 +1,47 @@ class SortedList { - constructor() {} + constructor(items, length) { + this.items = []; + this.length = 0; + } - add(item) {} + add(item) { + this.items.forEach(item => { + this.items.push(item); + this.items.sort((a, b) => a - b); + this.length = this.items.length; + }); + } - get(pos) {} + get(pos) { + if (pos < 0 || pos >= this.length) { + console.log("OutOfBounds"); + return; + } - max() {} + return this.items[pos]; + } +} - min() {} +max() { + if (this.length === 0) { + console.log("EmptySortedList"); + return; + } + return this.items[this.length - 1]; +} - sum() {} +min() { + if (this.length === 0) { + console.log("EmptySortedList"); + return; + } - avg() {} + return this.items[0]; } + +sum() { } + +avg() { } + module.exports = SortedList;