From a4a9d4c7a36a5437d448eaea0a86c861599fe0b5 Mon Sep 17 00:00:00 2001 From: Uzi Alam Date: Fri, 12 Dec 2025 06:13:29 +1100 Subject: [PATCH 1/2] Done --- .DS_Store | Bin 0 -> 8196 bytes index.js | 40 ++++++++++++++++++++++++++++++++++------ package.json | 6 +++++- 3 files changed, 39 insertions(+), 7 deletions(-) create mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..c2261ba5db8bdf9a6b511d59cc4e2c142251fe14 GIT binary patch literal 8196 zcmeHM&rcIU6n;~xYz1UNP>h;1_F^I;m?$P5tQBL3F_4xZ1hDLOhqAKF)ZHyVBqY7+ z(Ti6T{{Ry&Ue&uEy_)Dh;Keh(`OyN4+=wx8CYkx(%zNLwnQzHXX8{0GsCy#-0{~!Q z6=-*0^M@k*q8=zIJ<^FtkPqVluebqsv2P!UHUmZhqkvJsC}0#Y3j7NS;F&Fob;!A| zyrwk@7zO@I1;qOyi&bD=V?&{Qbzmc}0ElTEmIZD3(;qP_1`zWa8wzm*3sF==MJ4)* zLG;amC_4J{I=-P$(SgX!IFHUu^bLjRiwDWda3FbwrZox}1r918?(S(Af-3kBC+_bB z^bPIEB8lzII9P@{xQXa@iRcrpXdh>1z##;>pF=JtI2Nvgfd>>eko^RrMEuJ{e5agO z#Ft?eGkCbJ0DB2u+ouGt2WsFz1y-=FV*C|kaoLwy(PsNIw-pmJbS7pvgqISpsl6Iz zpa}Qi4vfJ=#35X@w?9)VOfb?AiybAOPU`z%aqfCl(_dlUyS2cN;^E=1B-NHacD&tc zw>qqa(lTE!#ZFw03QjmDdQ+SSZqs($X`il_?Y_I5#g5NtC<(qtF=YOc&pf_f;C1Fj zl3P*^D`REK_L;4%;lb?4$hGak?AFNWwVQ+4n>R+cw=-6M?&_^#c_mn7{5dWi3(@a# z=u-Vw`vR@jw*AVQ-VXWP+|D=KZf+=ZqNB6xWVhYZd#b0er@z1d^qGOPz30xC?NhE( zS*eC%p?7(}!$MG}WxG4V?T%MCn+)k1ZgVE48*#~hhOXWOp-8>QyF*i(HH_)o9gvgW z4=H7H)zJ4QmX;zK&+M^hMYc-FgJ6eLg2VGm|z7S$9#3h$6bh(%ao;>Q}J0fcl)Q3F_X(*QkD(5rm|LF)6z(C zALwgoPchCYk|vcWmw%uPJeM!y-)jlx;VCrW6}*AB@DaYi5BLQ;q>G#;7s+KZNUoDn zk|%dak<5`r;*ckbpK3nj3wk~cBtoP0kk?8f3plIdn2I;&|9-hl&nR%z3bd&S2gLpV z-r?W>k29NvS0TBMuESoz;8|7LUjND literal 0 HcmV?d00001 diff --git a/index.js b/index.js index 0f4b28b4..aeea2549 100644 --- a/index.js +++ b/index.js @@ -1,17 +1,45 @@ class SortedList { - constructor() {} + constructor() { + this.items = []; + this.length = []; + } - add(item) {} + add(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) { + throw new Error ("OutOfBounds"); + } + return this.items[pos]; + } - max() {} + max() { + if (this.length === 0) { + throw new Error ("EmptySortedList"); + } + return this.items[this.length - 1]; + } - min() {} + min() { + if (this.length === 0) { + throw new Error ("EmptySortedList") + } + return this.items[0]; + } sum() {} - avg() {} + avg() { + if (this.length === 0) { + throw new Error ("EmptySortedList"); + } + const total = this.sum(); + return total / this.length; + } } module.exports = SortedList; diff --git a/package.json b/package.json index 3a5127ae..2e1f0a9d 100644 --- a/package.json +++ b/package.json @@ -19,5 +19,9 @@ "intro" ], "author": "fer@ironhack.com", - "license": "MIT" + "license": "MIT", + "devDependencies": { + "chai": "^6.2.1", + "mocha": "^11.7.5" + } } From 38d527acc1d1558ed9653d1f6d1b6395cd52d2e5 Mon Sep 17 00:00:00 2001 From: Uzi Alam Date: Fri, 12 Dec 2025 06:26:58 +1100 Subject: [PATCH 2/2] updated --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index aeea2549..70f29616 100644 --- a/index.js +++ b/index.js @@ -1,7 +1,7 @@ class SortedList { constructor() { this.items = []; - this.length = []; + this.length = 0; } add(item) {