From 71fa218a8f7b7e014738432dadc1497470ae9ed9 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Fri, 24 Oct 2025 10:12:47 +0100 Subject: [PATCH 01/19] Add initial test file for mean calculations --- prep/mean.test.js | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 prep/mean.test.js diff --git a/prep/mean.test.js b/prep/mean.test.js new file mode 100644 index 000000000..e69de29bb From 927769b17de592f6887d046ba0bce8604ffcbd09 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Fri, 24 Oct 2025 10:13:42 +0100 Subject: [PATCH 02/19] Add mean.js file for mean calculations --- prep/mean.js | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 prep/mean.js diff --git a/prep/mean.js b/prep/mean.js new file mode 100644 index 000000000..e69de29bb From a393af9cf00e0164a447b9e3a607bb1b6e6b8dc1 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Sun, 26 Oct 2025 10:05:36 +0000 Subject: [PATCH 03/19] Remove mean.js and mean.test.js files --- prep/mean.js | 0 prep/mean.test.js | 0 2 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 prep/mean.js delete mode 100644 prep/mean.test.js diff --git a/prep/mean.js b/prep/mean.js deleted file mode 100644 index e69de29bb..000000000 diff --git a/prep/mean.test.js b/prep/mean.test.js deleted file mode 100644 index e69de29bb..000000000 From 057a7ddb96e3595d8ca9fb9bf9189e710ed75f16 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Mon, 27 Oct 2025 16:46:38 +0000 Subject: [PATCH 04/19] Update dependencies in package-lock.json to latest versions --- Sprint-1/package-lock.json | 186 ++++++++----------------------------- 1 file changed, 41 insertions(+), 145 deletions(-) diff --git a/Sprint-1/package-lock.json b/Sprint-1/package-lock.json index 83e427d0b..6e05c7a4d 100644 --- a/Sprint-1/package-lock.json +++ b/Sprint-1/package-lock.json @@ -27,14 +27,15 @@ } }, "node_modules/@babel/code-frame": { - "version": "7.25.7", - "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.25.7.tgz", - "integrity": "sha512-0xZJFNE5XMpENsgfHYTw8FbX4kv53mFLn2i3XPoq69LyhYSCBJtitaHx9QnsVTrsogI4Z3+HtEfZ2/GFPOtf5g==", + "version": "7.27.1", + "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.27.1.tgz", + "integrity": "sha512-cjQ7ZlQ0Mv3b47hABuTevyTuYN4i+loJKGeV9flcCgIK37cCXRh+L1bd3iBHlynerhQ7BhCkn2BPbQUL+rGqFg==", "dev": true, "license": "MIT", "dependencies": { - "@babel/highlight": "^7.25.7", - "picocolors": "^1.0.0" + "@babel/helper-validator-identifier": "^7.27.1", + "js-tokens": "^4.0.0", + "picocolors": "^1.1.1" }, "engines": { "node": ">=6.9.0" @@ -172,9 +173,9 @@ } }, "node_modules/@babel/helper-string-parser": { - "version": "7.25.7", - "resolved": "https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-7.25.7.tgz", - "integrity": "sha512-CbkjYdsJNHFk8uqpEkpCvRs3YRp9tY6FmFY7wLMSYuGYkrdUi7r2lc4/wqsvlHoMznX3WJ9IP8giGPq68T/Y6g==", + "version": "7.27.1", + "resolved": "https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-7.27.1.tgz", + "integrity": "sha512-qMlSxKbpRlAridDExk92nSobyDdpPijUq2DW6oDnUqd0iOGxmQjyqhMIihI9+zv4LPyZdRje2cavWPbCbWm3eA==", "dev": true, "license": "MIT", "engines": { @@ -182,9 +183,9 @@ } }, "node_modules/@babel/helper-validator-identifier": { - "version": "7.25.7", - "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.25.7.tgz", - "integrity": "sha512-AM6TzwYqGChO45oiuPqwL2t20/HdMC1rTPAesnBCgPCSF1x3oN9MVUwQV2iyz4xqWrctwK5RNC8LV22kaQCNYg==", + "version": "7.28.5", + "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.28.5.tgz", + "integrity": "sha512-qSs4ifwzKJSV39ucNjsvc6WVHs6b7S03sOh2OcHF9UHfVPqWWALUsNUVzhSBiItjRZoLHx7nIarVjqKVusUZ1Q==", "dev": true, "license": "MIT", "engines": { @@ -202,121 +203,27 @@ } }, "node_modules/@babel/helpers": { - "version": "7.25.7", - "resolved": "https://registry.npmjs.org/@babel/helpers/-/helpers-7.25.7.tgz", - "integrity": "sha512-Sv6pASx7Esm38KQpF/U/OXLwPPrdGHNKoeblRxgZRLXnAtnkEe4ptJPDtAZM7fBLadbc1Q07kQpSiGQ0Jg6tRA==", - "dev": true, - "license": "MIT", - "dependencies": { - "@babel/template": "^7.25.7", - "@babel/types": "^7.25.7" - }, - "engines": { - "node": ">=6.9.0" - } - }, - "node_modules/@babel/highlight": { - "version": "7.25.7", - "resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.25.7.tgz", - "integrity": "sha512-iYyACpW3iW8Fw+ZybQK+drQre+ns/tKpXbNESfrhNnPLIklLbXr7MYJ6gPEd0iETGLOK+SxMjVvKb/ffmk+FEw==", + "version": "7.28.4", + "resolved": "https://registry.npmjs.org/@babel/helpers/-/helpers-7.28.4.tgz", + "integrity": "sha512-HFN59MmQXGHVyYadKLVumYsA9dBFun/ldYxipEjzA4196jpLZd8UjEEBLkbEkvfYreDqJhZxYAWFPtrfhNpj4w==", "dev": true, "license": "MIT", "dependencies": { - "@babel/helper-validator-identifier": "^7.25.7", - "chalk": "^2.4.2", - "js-tokens": "^4.0.0", - "picocolors": "^1.0.0" + "@babel/template": "^7.27.2", + "@babel/types": "^7.28.4" }, "engines": { "node": ">=6.9.0" } }, - "node_modules/@babel/highlight/node_modules/ansi-styles": { - "version": "3.2.1", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", - "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", - "dev": true, - "license": "MIT", - "dependencies": { - "color-convert": "^1.9.0" - }, - "engines": { - "node": ">=4" - } - }, - "node_modules/@babel/highlight/node_modules/chalk": { - "version": "2.4.2", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", - "integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==", - "dev": true, - "license": "MIT", - "dependencies": { - "ansi-styles": "^3.2.1", - "escape-string-regexp": "^1.0.5", - "supports-color": "^5.3.0" - }, - "engines": { - "node": ">=4" - } - }, - "node_modules/@babel/highlight/node_modules/color-convert": { - "version": "1.9.3", - "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", - "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==", - "dev": true, - "license": "MIT", - "dependencies": { - "color-name": "1.1.3" - } - }, - "node_modules/@babel/highlight/node_modules/color-name": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", - "integrity": "sha512-72fSenhMw2HZMTVHeCA9KCmpEIbzWiQsjN+BHcBbS9vr1mtt+vJjPdksIBNUmKAW8TFUDPJK5SUU3QhE9NEXDw==", - "dev": true, - "license": "MIT" - }, - "node_modules/@babel/highlight/node_modules/escape-string-regexp": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", - "integrity": "sha512-vbRorB5FUQWvla16U8R/qgaFIya2qGzwDrNmCZuYKrbdSUMG6I1ZCGQRefkRVhuOkIGVne7BQ35DSfo1qvJqFg==", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=0.8.0" - } - }, - "node_modules/@babel/highlight/node_modules/has-flag": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", - "integrity": "sha512-sKJf1+ceQBr4SMkvQnBDNDtf4TXpVhVGateu0t918bl30FnbE2m4vNLX+VWe/dpjlb+HugGYzW7uQXH98HPEYw==", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=4" - } - }, - "node_modules/@babel/highlight/node_modules/supports-color": { - "version": "5.5.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", - "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", - "dev": true, - "license": "MIT", - "dependencies": { - "has-flag": "^3.0.0" - }, - "engines": { - "node": ">=4" - } - }, "node_modules/@babel/parser": { - "version": "7.25.8", - "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.25.8.tgz", - "integrity": "sha512-HcttkxzdPucv3nNFmfOOMfFf64KgdJVqm1KaCm25dPGMLElo9nsLvXeJECQg8UzPuBGLyTSA0ZzqCtDSzKTEoQ==", + "version": "7.28.5", + "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.28.5.tgz", + "integrity": "sha512-KKBU1VGYR7ORr3At5HAtUQ+TV3SzRCXmA/8OdDZiLDBIZxVyzXuztPjfLd3BV1PRAQGCMWWSHYhL0F8d5uHBDQ==", "dev": true, "license": "MIT", "dependencies": { - "@babel/types": "^7.25.8" + "@babel/types": "^7.28.5" }, "bin": { "parser": "bin/babel-parser.js" @@ -565,15 +472,15 @@ } }, "node_modules/@babel/template": { - "version": "7.25.7", - "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.25.7.tgz", - "integrity": "sha512-wRwtAgI3bAS+JGU2upWNL9lSlDcRCqD05BZ1n3X2ONLH1WilFP6O1otQjeMK/1g0pvYcXC7b/qVUB1keofjtZA==", + "version": "7.27.2", + "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.27.2.tgz", + "integrity": "sha512-LPDZ85aEJyYSd18/DkjNh4/y1ntkE5KwUHWTiqgRxruuZL2F1yuHligVHLvcHY2vMHXttKFpJn6LwfI7cw7ODw==", "dev": true, "license": "MIT", "dependencies": { - "@babel/code-frame": "^7.25.7", - "@babel/parser": "^7.25.7", - "@babel/types": "^7.25.7" + "@babel/code-frame": "^7.27.1", + "@babel/parser": "^7.27.2", + "@babel/types": "^7.27.1" }, "engines": { "node": ">=6.9.0" @@ -599,15 +506,14 @@ } }, "node_modules/@babel/types": { - "version": "7.25.8", - "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.25.8.tgz", - "integrity": "sha512-JWtuCu8VQsMladxVz/P4HzHUGCAwpuqacmowgXFs5XjxIgKuNjnLokQzuVjlTvIzODaDmpjT3oxcC48vyk9EWg==", + "version": "7.28.5", + "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.28.5.tgz", + "integrity": "sha512-qQ5m48eI/MFLQ5PxQj4PFaprjyCTLI37ElWMmNs0K8Lk3dVeOdNpB3ks8jc7yM5CDmVC73eMVk/trk3fgmrUpA==", "dev": true, "license": "MIT", "dependencies": { - "@babel/helper-string-parser": "^7.25.7", - "@babel/helper-validator-identifier": "^7.25.7", - "to-fast-properties": "^2.0.0" + "@babel/helper-string-parser": "^7.27.1", + "@babel/helper-validator-identifier": "^7.28.5" }, "engines": { "node": ">=6.9.0" @@ -1325,9 +1231,9 @@ "license": "MIT" }, "node_modules/brace-expansion": { - "version": "1.1.11", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", - "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", + "version": "1.1.12", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.12.tgz", + "integrity": "sha512-9T9UjW3r0UW5c1Q7GTwllptXwhvYmEzFhzMfZ9H7FQWt+uZePjZPjBP/W1ZEyZ1twGWom5/56TF4lPcqjnDHcg==", "dev": true, "license": "MIT", "dependencies": { @@ -1579,9 +1485,9 @@ } }, "node_modules/cross-spawn": { - "version": "7.0.3", - "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", - "integrity": "sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==", + "version": "7.0.6", + "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz", + "integrity": "sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==", "dev": true, "license": "MIT", "dependencies": { @@ -3153,9 +3059,9 @@ "license": "MIT" }, "node_modules/picocolors": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.1.0.tgz", - "integrity": "sha512-TQ92mBOW0l3LeMeyLV6mzy/kWr8lkd/hp3mTg7wYK7zJhuBStmGMBG0BdeDZS/dZx1IukaX6Bk11zcln25o1Aw==", + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.1.1.tgz", + "integrity": "sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA==", "dev": true, "license": "ISC" }, @@ -3543,16 +3449,6 @@ "dev": true, "license": "BSD-3-Clause" }, - "node_modules/to-fast-properties": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/to-fast-properties/-/to-fast-properties-2.0.0.tgz", - "integrity": "sha512-/OaKK0xYrs3DmxRYqL/yDc+FxFUVYhDlXMhRmv3z915w2HF1tnN1omB354j8VUGO/hbRzyD6Y3sA7v7GS/ceog==", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=4" - } - }, "node_modules/to-regex-range": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", From bc5e43c5fe57596e24fab3f169c65479b8bc5bf8 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Mon, 27 Oct 2025 16:47:09 +0000 Subject: [PATCH 05/19] Refactor calculateMedian function to handle mixed values and improve median calculation logic --- Sprint-1/fix/median.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/Sprint-1/fix/median.js b/Sprint-1/fix/median.js index b22590bc6..d750cf28b 100644 --- a/Sprint-1/fix/median.js +++ b/Sprint-1/fix/median.js @@ -6,9 +6,20 @@ // or 'list' has mixed values (the function is expected to sort only numbers). function calculateMedian(list) { - const middleIndex = Math.floor(list.length / 2); - const median = list.splice(middleIndex, 1)[0]; + const sortedList = [...list].sort((a, b) => a - b); + const middleIndex = Math.floor(sortedList.length / 2); + const listMiddleIndex = sortedList[middleIndex]; + const median = sortedList.slice(middleIndex)[0]; + + console.log(listMiddleIndex); + console.log(median); +if (!sortedList.every(element=>typeof element ==="number") ){ + return null +} + if (sortedList.length % 2 === 0) { + return (listMiddleIndex + (listMiddleIndex - 1)) / 2; + } return median; } - +console.log(calculateMedian([1, 6, 9, 12])); module.exports = calculateMedian; From b13a7314f54ee734416959041a7dd9cb2be1ced5 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Mon, 27 Oct 2025 16:47:30 +0000 Subject: [PATCH 06/19] Add workspace configuration for project structure and Jest settings --- Module-Data-Groups.code-workspace | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 Module-Data-Groups.code-workspace diff --git a/Module-Data-Groups.code-workspace b/Module-Data-Groups.code-workspace new file mode 100644 index 000000000..9860d77f6 --- /dev/null +++ b/Module-Data-Groups.code-workspace @@ -0,0 +1,20 @@ +{ + "folders": [ + { + "name": "Sprint-1", + "path": "./Sprint-1" + }, + { + "name": "Sprint-2", + "path": "./Sprint-2" + }, + { + "name": "Sprint-3", + "path": "./Sprint-3" + } + ], + "settings": { + "jest.disabledWorkspaceFolders": ["Sprint-2", "Sprint-3"], + "jest.jestCommandLine": "npm test --" + } +} From 552eb4c1a0dddd3c7402f81d41701bba0d1c243d Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Mon, 27 Oct 2025 17:39:08 +0000 Subject: [PATCH 07/19] Refactor calculateMedian function to filter non-numeric values and improve null handling --- Sprint-1/fix/median.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/Sprint-1/fix/median.js b/Sprint-1/fix/median.js index d750cf28b..f859058cd 100644 --- a/Sprint-1/fix/median.js +++ b/Sprint-1/fix/median.js @@ -7,16 +7,24 @@ function calculateMedian(list) { const sortedList = [...list].sort((a, b) => a - b); - const middleIndex = Math.floor(sortedList.length / 2); - const listMiddleIndex = sortedList[middleIndex]; - const median = sortedList.slice(middleIndex)[0]; + const filteredList=sortedList.filter((element)=> typeof element==="number") + const middleIndex = Math.floor(filteredList.length / 2); + const listMiddleIndex = filteredList[middleIndex]; + const median = filteredList.slice(middleIndex)[0]; console.log(listMiddleIndex); console.log(median); -if (!sortedList.every(element=>typeof element ==="number") ){ + if(!Array.isArray(list)){ + return null + } + if(list.length===0){ + return null + } +if (filteredList.length===0 ){ return null } - if (sortedList.length % 2 === 0) { + + if (filteredList.length % 2 === 0) { return (listMiddleIndex + (listMiddleIndex - 1)) / 2; } return median; From 1e0393eaf49109544b721330e5a856283388ae4f Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Mon, 27 Oct 2025 17:45:27 +0000 Subject: [PATCH 08/19] Refactor calculateMedian function to improve null checks and remove redundant code --- Sprint-1/fix/median.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Sprint-1/fix/median.js b/Sprint-1/fix/median.js index f859058cd..df6d258bc 100644 --- a/Sprint-1/fix/median.js +++ b/Sprint-1/fix/median.js @@ -6,20 +6,20 @@ // or 'list' has mixed values (the function is expected to sort only numbers). function calculateMedian(list) { + if (!Array.isArray(list)) { + return null; + } + if (list.length === 0) { + return null; + } const sortedList = [...list].sort((a, b) => a - b); const filteredList=sortedList.filter((element)=> typeof element==="number") const middleIndex = Math.floor(filteredList.length / 2); const listMiddleIndex = filteredList[middleIndex]; const median = filteredList.slice(middleIndex)[0]; - console.log(listMiddleIndex); - console.log(median); - if(!Array.isArray(list)){ - return null - } - if(list.length===0){ - return null - } + + if (filteredList.length===0 ){ return null } From b78089c4c29b80242d15439a7fefcd8dd0f394c0 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Mon, 27 Oct 2025 17:56:27 +0000 Subject: [PATCH 09/19] Refactor calculateMedian function to streamline sorting and improve median calculation logic --- Sprint-1/fix/median.js | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/Sprint-1/fix/median.js b/Sprint-1/fix/median.js index df6d258bc..53d41bff2 100644 --- a/Sprint-1/fix/median.js +++ b/Sprint-1/fix/median.js @@ -12,22 +12,21 @@ function calculateMedian(list) { if (list.length === 0) { return null; } - const sortedList = [...list].sort((a, b) => a - b); - const filteredList=sortedList.filter((element)=> typeof element==="number") - const middleIndex = Math.floor(filteredList.length / 2); - const listMiddleIndex = filteredList[middleIndex]; - const median = filteredList.slice(middleIndex)[0]; + const filteredList = list.filter((element) => typeof element === "number"); + const sortedList = filteredList.sort((a, b) => a - b); - - -if (filteredList.length===0 ){ - return null -} + const middleIndex = Math.floor(sortedList.length / 2); + + const median = sortedList.slice(middleIndex)[0]; + + if (sortedList.length === 0) { + return null; + } - if (filteredList.length % 2 === 0) { - return (listMiddleIndex + (listMiddleIndex - 1)) / 2; + if (sortedList.length % 2 === 0) { + return (sortedList[middleIndex] + sortedList[middleIndex - 1]) / 2; } return median; } -console.log(calculateMedian([1, 6, 9, 12])); + module.exports = calculateMedian; From 4f6b45e50255a56677ffee7afb7f8dd7261efed6 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Mon, 27 Oct 2025 18:43:13 +0000 Subject: [PATCH 10/19] Add tests for findMax function to cover various input scenarios --- Sprint-1/implement/max.test.js | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/Sprint-1/implement/max.test.js b/Sprint-1/implement/max.test.js index 82f18fd88..87bd6ea47 100644 --- a/Sprint-1/implement/max.test.js +++ b/Sprint-1/implement/max.test.js @@ -16,28 +16,48 @@ const findMax = require("./max.js"); // When passed to the max function // Then it should return -Infinity // Delete this test.todo and replace it with a test. -test.todo("given an empty array, returns -Infinity"); +test("given an empty array, returns -Infinity", () => { + expect(findMax([])).toEqual(-Infinity); +}); // Given an array with one number // When passed to the max function // Then it should return that number +test("Given an array with one number,returns that number", () => { + expect(findMax([4])).toEqual(4); +}); // Given an array with both positive and negative numbers // When passed to the max function // Then it should return the largest number overall +test("Given an array with both positive and negative numbers,return the largest number overall", () => { + expect(findMax([-9, 4])).toEqual(4); +}); // Given an array with just negative numbers // When passed to the max function // Then it should return the closest one to zero +test("Given an array with just negative numbers,return the closest one to zero", () => { + expect(findMax([-3, -1, -9, -6])).toEqual(-1); +}); // Given an array with decimal numbers // When passed to the max function // Then it should return the largest decimal number +test("Given an array with decimal numbers,return the largest decimal number", () => { + expect(findMax([4.7, 4.1, 9.5, 1.3])).toEqual(9.5); +}); // Given an array with non-number values // When passed to the max function // Then it should return the max and ignore non-numeric values +test("Given an array with non-number values,return the max and ignore non-numeric values", () => { + expect(findMax(["99", 4, null, "h", 2, 3.9])).toEqual(4); +}); // Given an array with only non-number values // When passed to the max function // Then it should return the least surprising value given how it behaves for all other inputs +test("Given an array with only non-number values,return isNaN", () => { + expect(findMax([null, undefined, "8", "g"])).toBeNaN(); +}); From 5d670eca67a4854201612ecdbc14d0b641e7ae59 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Mon, 27 Oct 2025 18:43:23 +0000 Subject: [PATCH 11/19] Refactor findMax function to enhance readability and maintainability --- Sprint-1/implement/max.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Sprint-1/implement/max.js b/Sprint-1/implement/max.js index 6dd76378e..2129e1350 100644 --- a/Sprint-1/implement/max.js +++ b/Sprint-1/implement/max.js @@ -1,4 +1,17 @@ function findMax(elements) { + if (elements.length === 0) { + return -Infinity; + } else if (elements.length === 1) { + return elements[0]; + } + if (elements.every((element) => typeof element !== "number")) { + return NaN; + } + let filteredElements = elements.filter( + (element) => typeof element === "number" + ); + let orderedElements = filteredElements.sort((a, b) => a - b); + return orderedElements[orderedElements.length - 1]; } module.exports = findMax; From 879eb0e5ffd9b5e1821cc38f35c387c72a1c43a7 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Mon, 27 Oct 2025 21:02:49 +0000 Subject: [PATCH 12/19] Implement tests for sum function to validate various input scenarios --- Sprint-1/implement/sum.test.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/Sprint-1/implement/sum.test.js b/Sprint-1/implement/sum.test.js index dd0a090ca..4bbfb9ec9 100644 --- a/Sprint-1/implement/sum.test.js +++ b/Sprint-1/implement/sum.test.js @@ -13,24 +13,41 @@ const sum = require("./sum.js"); // Given an empty array // When passed to the sum function // Then it should return 0 -test.todo("given an empty array, returns 0") +test("given an empty array, returns 0", () => { + expect(sum([])).toEqual(0); +}); // Given an array with just one number // When passed to the sum function // Then it should return that number +test("Given an array with just one number,return that number", () => { + expect(sum([5])).toEqual(5); +}); // Given an array containing negative numbers // When passed to the sum function // Then it should still return the correct total sum +test("Given an array containing negative numbers,return the correct total sum", () => { + expect(sum([-6, -7, -2])).toEqual(-15); +}); // Given an array with decimal/float numbers // When passed to the sum function // Then it should return the correct total sum +test("Given an array with decimal/float numbers,return the correct total sum", () => { + expect(sum([-1.5, 1.5, 4.5])).toEqual(4.5); +}); // Given an array containing non-number values // When passed to the sum function // Then it should ignore the non-numerical values and return the sum of the numerical elements +test("Given an array containing non-number values,it should ignore the non-numerical values and return the sum of the numerical elements", () => { + expect(sum([null, "g", "9", 1.2, 1.8, -3])).toEqual(0); +}); // Given an array with only non-number values // When passed to the sum function // Then it should return the least surprising value given how it behaves for all other inputs +test("Given an array with only non-number values,return Nan", () => { + expect(sum(["g", undefined, null, "7", []])).toBeNaN(); +}); From 157b5f777bab4085d91e9e3f6395fe9b8719b597 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Mon, 27 Oct 2025 21:02:59 +0000 Subject: [PATCH 13/19] Implement sum function to calculate the sum of an array of numbers --- Sprint-1/implement/sum.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/Sprint-1/implement/sum.js b/Sprint-1/implement/sum.js index 9062aafe3..0c3bdd947 100644 --- a/Sprint-1/implement/sum.js +++ b/Sprint-1/implement/sum.js @@ -1,4 +1,22 @@ function sum(elements) { -} + if (elements.length === 0) { + return 0; + } + if (elements.length === 1) { + return elements[0]; + } + if (elements.every((element) => typeof element !== "number")) { + return NaN; + } + const filteredElements = elements.filter( + (element) => typeof element === "number" + ); + let addElements = 0; + for (let element of filteredElements) { + addElements = addElements + element; + } + return addElements; +} module.exports = sum; +console.log(sum([-9, -3, -4])); From c85cfda3bb569078877c8eabc60a3e4c5edc75db Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Thu, 30 Oct 2025 10:35:54 +0000 Subject: [PATCH 14/19] Implement tests for dedupe function to validate various input scenarios --- Sprint-1/implement/dedupe.test.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Sprint-1/implement/dedupe.test.js b/Sprint-1/implement/dedupe.test.js index 23e0f8638..c10d5022f 100644 --- a/Sprint-1/implement/dedupe.test.js +++ b/Sprint-1/implement/dedupe.test.js @@ -16,12 +16,20 @@ E.g. dedupe([1, 2, 1]) target output: [1, 2] // Given an empty array // When passed to the dedupe function // Then it should return an empty array -test.todo("given an empty array, it returns an empty array"); +test("given an empty array, it returns an empty array",()=>{ + expect(dedupe([])).toEqual([]) +}); // Given an array with no duplicates // When passed to the dedupe function // Then it should return a copy of the original array +test("Given an array with no duplicates,return a copy of the original array",()=>{ + expect(dedupe([1, "y", 4, 7])).toEqual([1, "y", 4, 7]); +}); // Given an array with strings or numbers // When passed to the dedupe function // Then it should remove the duplicate values, preserving the first occurence of each element +test("Given an array with strings or numbers,return an array without duplicates",()=>{ + expect(dedupe([1, 1, "l", 5, 7, "l"])).toEqual([1,"l", 5, 7]); +}); \ No newline at end of file From 5619c221c48feea68b8832d88c25277af556cf2e Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Thu, 30 Oct 2025 10:36:07 +0000 Subject: [PATCH 15/19] Implement dedupe function to remove duplicate values from an array --- Sprint-1/implement/dedupe.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Sprint-1/implement/dedupe.js b/Sprint-1/implement/dedupe.js index 781e8718a..21a7e6ba2 100644 --- a/Sprint-1/implement/dedupe.js +++ b/Sprint-1/implement/dedupe.js @@ -1 +1,11 @@ -function dedupe() {} +function dedupe(arr) { + if (arr.length===0){ + return [] + } + const arrCopy = arr.slice(0); + console.log(arrCopy); + return [...new Set(arrCopy)]; +} +module.exports=dedupe; + +console.log(dedupe([1,2,3,4,4,2])); From abd3a4365b47c506af9fcbf1e21c411cd88c5111 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Thu, 30 Oct 2025 11:03:07 +0000 Subject: [PATCH 16/19] Format code for consistency and readability in dedupe function --- Sprint-1/implement/dedupe.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Sprint-1/implement/dedupe.js b/Sprint-1/implement/dedupe.js index 21a7e6ba2..0592c0c89 100644 --- a/Sprint-1/implement/dedupe.js +++ b/Sprint-1/implement/dedupe.js @@ -1,11 +1,11 @@ function dedupe(arr) { - if (arr.length===0){ - return [] - } - const arrCopy = arr.slice(0); - console.log(arrCopy); - return [...new Set(arrCopy)]; + if (arr.length === 0) { + return []; + } + const arrCopy = arr.slice(0); + console.log(arrCopy); + return [...new Set(arrCopy)]; } -module.exports=dedupe; +module.exports = dedupe; -console.log(dedupe([1,2,3,4,4,2])); +console.log(dedupe([1, 2, 3, 4, 4, 2])); From ee2fd08bc7060cd2e4156cbd07745b21906d9b51 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Thu, 30 Oct 2025 11:03:17 +0000 Subject: [PATCH 17/19] Format dedupe tests for consistency and readability --- Sprint-1/implement/dedupe.test.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Sprint-1/implement/dedupe.test.js b/Sprint-1/implement/dedupe.test.js index c10d5022f..c1e357062 100644 --- a/Sprint-1/implement/dedupe.test.js +++ b/Sprint-1/implement/dedupe.test.js @@ -16,20 +16,20 @@ E.g. dedupe([1, 2, 1]) target output: [1, 2] // Given an empty array // When passed to the dedupe function // Then it should return an empty array -test("given an empty array, it returns an empty array",()=>{ - expect(dedupe([])).toEqual([]) +test("given an empty array, it returns an empty array", () => { + expect(dedupe([])).toEqual([]); }); // Given an array with no duplicates // When passed to the dedupe function // Then it should return a copy of the original array -test("Given an array with no duplicates,return a copy of the original array",()=>{ - expect(dedupe([1, "y", 4, 7])).toEqual([1, "y", 4, 7]); +test("Given an array with no duplicates,return a copy of the original array", () => { + expect(dedupe([1, "y", 4, 7])).toEqual([1, "y", 4, 7]); }); // Given an array with strings or numbers // When passed to the dedupe function // Then it should remove the duplicate values, preserving the first occurence of each element -test("Given an array with strings or numbers,return an array without duplicates",()=>{ - expect(dedupe([1, 1, "l", 5, 7, "l"])).toEqual([1,"l", 5, 7]); -}); \ No newline at end of file +test("Given an array with strings or numbers,return an array without duplicates", () => { + expect(dedupe([1, 1, "l", 5, 7, "l"])).toEqual([1, "l", 5, 7]); +}); From 584bd6f52c0000034bbb947535e89d6a0ddb582c Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Thu, 30 Oct 2025 11:08:59 +0000 Subject: [PATCH 18/19] Fix spacing in comment for consistency in includes tests --- Sprint-1/refactor/includes.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-1/refactor/includes.test.js b/Sprint-1/refactor/includes.test.js index 812158470..6f57c6d2d 100644 --- a/Sprint-1/refactor/includes.test.js +++ b/Sprint-1/refactor/includes.test.js @@ -1,4 +1,4 @@ -// Refactored version of includes should still pass the tests below: +// Refactored version of includes should still pass the tests below : const includes = require("./includes.js"); From 908c81ea18cb2fb9f89e992042a8ec403ebf336d Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Thu, 30 Oct 2025 11:09:11 +0000 Subject: [PATCH 19/19] Refactor includes function to use for...of loop for improved readability --- Sprint-1/refactor/includes.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Sprint-1/refactor/includes.js b/Sprint-1/refactor/includes.js index 29dad81f0..8c9ae2e66 100644 --- a/Sprint-1/refactor/includes.js +++ b/Sprint-1/refactor/includes.js @@ -1,8 +1,7 @@ // Refactor the implementation of includes to use a for...of loop function includes(list, target) { - for (let index = 0; index < list.length; index++) { - const element = list[index]; + for (const element of list) { if (element === target) { return true; }