From cb3d8e05c81df8f1a240748c9cee80f4294ad25e Mon Sep 17 00:00:00 2001 From: AngelaMcLeary Date: Fri, 6 Mar 2026 19:17:01 +0000 Subject: [PATCH 1/9] Jest test for first case --- Sprint-1/implement/dedupe.test.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Sprint-1/implement/dedupe.test.js b/Sprint-1/implement/dedupe.test.js index 23e0f8638..bc023efe4 100644 --- a/Sprint-1/implement/dedupe.test.js +++ b/Sprint-1/implement/dedupe.test.js @@ -16,7 +16,11 @@ 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 array has no duplicates, it returns a copy of the original array", () => { + expect(dedupe([1, 2, 3])).toEqual([1, 2, 3]); + + expect(dedupe([5, 1, 4])).toEqual([5, 1, 4]); +}); // Given an array with no duplicates // When passed to the dedupe function From 20843ced1012b72c5bcd75e78ec82e51e1f31c17 Mon Sep 17 00:00:00 2001 From: AngelaMcLeary Date: Sat, 7 Mar 2026 22:28:39 +0000 Subject: [PATCH 2/9] completed dedupe.js and dedupe.test.js formatted with prettier --- Sprint-1/implement/dedupe.js | 20 ++- Sprint-1/implement/dedupe.test.js | 16 ++- Sprint-1/package-lock.json | 198 +++++++----------------------- 3 files changed, 78 insertions(+), 156 deletions(-) diff --git a/Sprint-1/implement/dedupe.js b/Sprint-1/implement/dedupe.js index 781e8718a..e97719b05 100644 --- a/Sprint-1/implement/dedupe.js +++ b/Sprint-1/implement/dedupe.js @@ -1 +1,19 @@ -function dedupe() {} +function dedupe(arr) { + if (arr.length === 0) { //checks if array is empty + return arr; + } + const newArray = []; // to store the new values after checking and deduplicating + for (let i = 0; i < arr.length; i++) { // checks every item in array for dupes + if (!newArray.includes(arr[i])) { //checks if new item is already in newArray + newArray.push(arr[i]);// adds new item !in newArray and appends it + } + } + return newArray; // returns new array without duplicates/empty +} + +console.log(dedupe([])); // prints: [] +console.log(dedupe([1, 2, 3])); // prints: [ 1, 2, 3 ] +console.log(dedupe([5, 1, 1, 2, 3, 2, 5, 8])); // prints: [ 5, 1, 2, 3, 8 ] +console.log(dedupe(["a", "a", "a", "b", "b", "c"])); // prints: [ 'a', 'b', 'c' ] + +module.exports = dedupe; diff --git a/Sprint-1/implement/dedupe.test.js b/Sprint-1/implement/dedupe.test.js index bc023efe4..a2e8ad190 100644 --- a/Sprint-1/implement/dedupe.test.js +++ b/Sprint-1/implement/dedupe.test.js @@ -16,16 +16,24 @@ 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 array has no duplicates, it returns a copy of the original array", () => { - expect(dedupe([1, 2, 3])).toEqual([1, 2, 3]); - - expect(dedupe([5, 1, 4])).toEqual([5, 1, 4]); +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 has no duplicates, it returns a copy of the original array", () => { + expect(dedupe([1, 2, 3])).toEqual([1, 2, 3]); + expect(dedupe([5, 1, 4])).toEqual([5, 1, 4]); +}); // 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, it removes the duplicates preserving the first occurrence of each element", () => { + expect(dedupe([5, 1, 1, 2, 3, 2, 5, 8])).toEqual([5, 1, 2, 3, 8]); + expect(dedupe([1, 2, 1])).toEqual([1, 2]); + expect(dedupe(["a", "a", "a", "b", "b", "c"])).toEqual(["a", "b", "c"]); + expect(dedupe(["z", "y", "w", "w", "u", "u"])).toEqual(["z", "y", "w", "u"]); +}); diff --git a/Sprint-1/package-lock.json b/Sprint-1/package-lock.json index 83e427d0b..bcb66f8d6 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.29.0", + "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.29.0.tgz", + "integrity": "sha512-9NhCeYjq9+3uxgdtp20LSiJXJvN0FeCtNGpJxuMFZ1Kv3cWUNb6DOhJwUvcVCzKGR66cw4njwM6hrJLqgOwbcw==", "dev": true, "license": "MIT", "dependencies": { - "@babel/highlight": "^7.25.7", - "picocolors": "^1.0.0" + "@babel/helper-validator-identifier": "^7.28.5", + "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==", + "version": "7.28.6", + "resolved": "https://registry.npmjs.org/@babel/helpers/-/helpers-7.28.6.tgz", + "integrity": "sha512-xOBvwq86HHdB7WUDTfKfT/Vuxh7gElQ+Sfti2Cy6yIWNW05P8iUslOVcZ4/sKbE+/jQaukQAdz/gf3724kYdqw==", "dev": true, "license": "MIT", "dependencies": { - "@babel/template": "^7.25.7", - "@babel/types": "^7.25.7" + "@babel/template": "^7.28.6", + "@babel/types": "^7.28.6" }, "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==", - "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" - }, - "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.29.0", + "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.29.0.tgz", + "integrity": "sha512-IyDgFV5GeDUVX4YdF/3CPULtVGSXXMLh1xVIgdCgxApktqnQV0r7/8Nqthg+8YLGaAtdyIlo2qIdZrbCv4+7ww==", "dev": true, "license": "MIT", "dependencies": { - "@babel/types": "^7.25.8" + "@babel/types": "^7.29.0" }, "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.28.6", + "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.28.6.tgz", + "integrity": "sha512-YA6Ma2KsCdGb+WC6UpBVFJGXL58MDA6oyONbjyF/+5sBgxY/dwkhLogbMT2GXXyU84/IhRw/2D1Os1B/giz+BQ==", "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.28.6", + "@babel/parser": "^7.28.6", + "@babel/types": "^7.28.6" }, "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.29.0", + "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.29.0.tgz", + "integrity": "sha512-LwdZHpScM4Qz8Xw2iKSzS+cfglZzJGvofQICy7W7v4caru4EaAmyUuO6BGrbyQ2mYV11W0U8j5mBhd14dd3B0A==", "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": { @@ -2785,9 +2691,9 @@ "license": "MIT" }, "node_modules/js-yaml": { - "version": "3.14.1", - "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.14.1.tgz", - "integrity": "sha512-okMH7OXXJ7YrN9Ok3/SXrnu4iX9yOk+25nqX4imS2npuvTYDmo/QEZoqwZkYaIDk3jVvBOTOIEgEhaLOynBS9g==", + "version": "3.14.2", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.14.2.tgz", + "integrity": "sha512-PMSmkqxr106Xa156c2M265Z+FTrPl+oxd/rgOQy2tijQeK5TxQ43psO1ZCwhVOSdnn+RzkzlRz/eY4BgJBYVpg==", "dev": true, "license": "MIT", "dependencies": { @@ -2952,9 +2858,9 @@ } }, "node_modules/minimatch": { - "version": "3.1.2", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", - "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", + "version": "3.1.5", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.5.tgz", + "integrity": "sha512-VgjWUsnnT6n+NUk6eZq77zeFdpW2LWDzP6zFGrCbHXiYNul5Dzqk2HHQ5uFH2DNW5Xbp8+jVzaeNt94ssEEl4w==", "dev": true, "license": "ISC", "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 4d92ad909cd4166fcb92ad28e0089c07e981f307 Mon Sep 17 00:00:00 2001 From: AngelaMcLeary Date: Sat, 7 Mar 2026 22:43:13 +0000 Subject: [PATCH 3/9] add first 3 Jest tests to max.test.js --- Sprint-1/implement/dedupe.js | 11 +++++++---- Sprint-1/implement/max.test.js | 9 ++++++++- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/Sprint-1/implement/dedupe.js b/Sprint-1/implement/dedupe.js index e97719b05..4eb65e893 100644 --- a/Sprint-1/implement/dedupe.js +++ b/Sprint-1/implement/dedupe.js @@ -1,11 +1,14 @@ function dedupe(arr) { - if (arr.length === 0) { //checks if array is empty + if (arr.length === 0) { + //checks if array is empty return arr; } const newArray = []; // to store the new values after checking and deduplicating - for (let i = 0; i < arr.length; i++) { // checks every item in array for dupes - if (!newArray.includes(arr[i])) { //checks if new item is already in newArray - newArray.push(arr[i]);// adds new item !in newArray and appends it + for (let i = 0; i < arr.length; i++) { + // checks every item in array for dupes + if (!newArray.includes(arr[i])) { + //checks if new item is already in newArray + newArray.push(arr[i]); // adds new item !in newArray and appends it } } return newArray; // returns new array without duplicates/empty diff --git a/Sprint-1/implement/max.test.js b/Sprint-1/implement/max.test.js index 82f18fd88..26e97820b 100644 --- a/Sprint-1/implement/max.test.js +++ b/Sprint-1/implement/max.test.js @@ -16,15 +16,22 @@ 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, it 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, it returns that number", () => { + expect(findMax([1])).toEqual(1); +}); // 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 positive and negative numbers, it returns the largest overall number", () => { + expect(findMax([-5, 35, 15, -55])).toEqual(35); // Given an array with just negative numbers // When passed to the max function From 0be696167e154a1b5810522b7da18a1c1e1f6c9d Mon Sep 17 00:00:00 2001 From: AngelaMcLeary Date: Sat, 7 Mar 2026 23:17:55 +0000 Subject: [PATCH 4/9] add all Jest tests to max.test.js --- Sprint-1/implement/max.test.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Sprint-1/implement/max.test.js b/Sprint-1/implement/max.test.js index 26e97820b..85a3616c8 100644 --- a/Sprint-1/implement/max.test.js +++ b/Sprint-1/implement/max.test.js @@ -32,19 +32,35 @@ test("given an array with one number, it returns that number", () => { // Then it should return the largest number overall test("given an array with positive and negative numbers, it returns the largest overall number", () => { expect(findMax([-5, 35, 15, -55])).toEqual(35); +}); // 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, returns the closest to zero", () => { + expect(findMax([-55, -35, -15, -5])).toEqual(-5); +}); + // 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, it returns the largest decimal number", () => { + expect(findMax([5.5, 3.5, 1.5, 0.5])).toEqual(5.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("ignores non-number values and returns the max number", () => { + expect(findMax(["Not", "A", "Number", 75, 85, 105])).toEqual(105); +}); + // 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 non-number values, returns Not a Number (NaN)", () => { + expect(findMax(["a", "b", "c"])).toEqual(NaN); +}); From d95136c1e880dea50a3d8cb18c090e52505227cb Mon Sep 17 00:00:00 2001 From: AngelaMcLeary Date: Tue, 10 Mar 2026 21:52:46 +0000 Subject: [PATCH 5/9] impemented code for mdeian.js and tested against median.test.js --- Sprint-1/fix/median.js | 34 ++++++++++++++++++++++++++++++---- Sprint-1/implement/max.test.js | 2 +- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/Sprint-1/fix/median.js b/Sprint-1/fix/median.js index b22590bc6..e83021de7 100644 --- a/Sprint-1/fix/median.js +++ b/Sprint-1/fix/median.js @@ -6,9 +6,35 @@ // 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]; - return median; + if (!Array.isArray(list) || list.length === 0) return null; + //If the items are not an array or if the array is empty return null + const numbers = list.filter((num) => typeof num === "number"); + if (numbers.length === 0) return null; + //checks the array before sorting and removing anything that is not a valid item ie not a number. + const sortedList = [...numbers].sort((a, b) => a - b); + //creates a copy, after sorting so the original items are kept the same. + const middleIndex = Math.floor(sortedList.length / 2); + //finds the median position + if (sortedList.length % 2 === 0) { + // if the list length is even, average the two middle numbers + return (sortedList[middleIndex - 1] + sortedList[middleIndex]) / 2; + //It finds the middles of the array and selects the number before the middle and and adds the next number then divides by 2 when number is even. + } + return sortedList[middleIndex]; + //if it is odd it returns the middle number } - +//checking +// console.log(calculateMedian([1, 2, "3", null, undefined, 4])); // 2 +// console.log(calculateMedian([1, 2, 3, 4])); // 2.5 +// console.log(calculateMedian([110, 20, 0])); //20 +// console.log(calculateMedian([1, "apple", 2, null, 5, undefined])); // 2 +// console.log(calculateMedian("not array")); // null +// console.log(calculateMedian("")); // null module.exports = calculateMedian; + +//check list +// Is the input valid? ie not a string? +//Validate what is valid input should be +// sort input and put in new array +//calculate median +//check output diff --git a/Sprint-1/implement/max.test.js b/Sprint-1/implement/max.test.js index 85a3616c8..c8316c4fc 100644 --- a/Sprint-1/implement/max.test.js +++ b/Sprint-1/implement/max.test.js @@ -62,5 +62,5 @@ test("ignores non-number values and returns the max number", () => { // 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 non-number values, returns Not a Number (NaN)", () => { - expect(findMax(["a", "b", "c"])).toEqual(NaN); + expect(findMax(["a", "b", "c"])).toBeNaN() // note: NaN !== NaN, }); From a0c1cedcfc3ade8abff0139cef111e616cbb1d13 Mon Sep 17 00:00:00 2001 From: AngelaMcLeary Date: Tue, 10 Mar 2026 22:33:33 +0000 Subject: [PATCH 6/9] implemented first version of max.js --- Sprint-1/implement/max.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Sprint-1/implement/max.js b/Sprint-1/implement/max.js index 6dd76378e..435d4602a 100644 --- a/Sprint-1/implement/max.js +++ b/Sprint-1/implement/max.js @@ -1,4 +1,14 @@ function findMax(elements) { + if (!Array.isArray(elements)) return null; + + const numbers = elements.filter((num) => typeof num === "number"); + if (numbers.length === 0) return null; + + const sortedElements = [...numbers].sort((a, b) => a - b); + + return Math.max(...sortedElements); } +//console.log(findMax([200, 5, 8, 15, 90, 12])); + module.exports = findMax; From c9385554c6667547665cbdaa49646ca29be44096 Mon Sep 17 00:00:00 2001 From: AngelaMcLeary Date: Thu, 12 Mar 2026 11:09:33 +0000 Subject: [PATCH 7/9] fixed max,js implementation, complted sum.js --- Sprint-1/implement/max.js | 12 +++++------- Sprint-1/implement/max.test.js | 4 ++-- Sprint-1/implement/sum.js | 15 +++++++++++++-- Sprint-1/implement/sum.test.js | 20 ++++++++++++++++++-- Sprint-1/refactor/includes.js | 9 +++------ 5 files changed, 41 insertions(+), 19 deletions(-) diff --git a/Sprint-1/implement/max.js b/Sprint-1/implement/max.js index 435d4602a..749ac12fa 100644 --- a/Sprint-1/implement/max.js +++ b/Sprint-1/implement/max.js @@ -1,14 +1,12 @@ function findMax(elements) { if (!Array.isArray(elements)) return null; + if (elements.length === 0) return -Infinity; +// must include declaration for infinity or test fails. const numbers = elements.filter((num) => typeof num === "number"); - if (numbers.length === 0) return null; - - const sortedElements = [...numbers].sort((a, b) => a - b); - - return Math.max(...sortedElements); + if (numbers.length === 0) return NaN; + // it returns NaN if no numbers found, there is no need to sort the numbers + return Math.max(...numbers); } - //console.log(findMax([200, 5, 8, 15, 90, 12])); - module.exports = findMax; diff --git a/Sprint-1/implement/max.test.js b/Sprint-1/implement/max.test.js index c8316c4fc..d4af03488 100644 --- a/Sprint-1/implement/max.test.js +++ b/Sprint-1/implement/max.test.js @@ -17,7 +17,7 @@ const findMax = require("./max.js"); // Then it should return -Infinity // Delete this test.todo and replace it with a test. test("given an empty array, it returns -Infinity", () => { - expect(findMax([])).toEqual(-Infinity); + expect(findMax([])).toBe(-Infinity) }); // Given an array with one number @@ -62,5 +62,5 @@ test("ignores non-number values and returns the max number", () => { // 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 non-number values, returns Not a Number (NaN)", () => { - expect(findMax(["a", "b", "c"])).toBeNaN() // note: NaN !== NaN, + expect(findMax(["a", "b", "c"])).toBeNaN(); // note: NaN !== NaN, }); diff --git a/Sprint-1/implement/sum.js b/Sprint-1/implement/sum.js index 9062aafe3..5860f35ad 100644 --- a/Sprint-1/implement/sum.js +++ b/Sprint-1/implement/sum.js @@ -1,4 +1,15 @@ function sum(elements) { -} + const numbers = elements.filter((value) => typeof value === "number"); + + if (numbers.length === 0 && elements.length > 0) return NaN; -module.exports = sum; + return numbers.reduce((total, nextNumber) => total + nextNumber, 0); +} +console.log(sum([])); // 0 +console.log(sum([1]));// 1 +console.log(sum([5, 2, -3]));//4 +console.log(sum([1.5, 2.5, 3.5]));//7.5 +console.log(sum(["h", 2.5, "e", 3.5]));//6 +console.log(sum(["a", "b", "c", "d"]));//Nan +6 +module.exports = sum; \ No newline at end of file diff --git a/Sprint-1/implement/sum.test.js b/Sprint-1/implement/sum.test.js index dd0a090ca..cd13f4ae6 100644 --- a/Sprint-1/implement/sum.test.js +++ b/Sprint-1/implement/sum.test.js @@ -13,24 +13,40 @@ 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, it 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, it returns that number", () => { + expect(sum([1])).toEqual(1); +}); // 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, it returns the correct sum", () => { + expect(sum([5, 2, -3])).toEqual(4); +}); // 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, it should return the total sum", () => { + expect(sum([1.5, 2.5, 3.5])).toEqual(7.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-numbers and sum the numerical elements", () => { + expect(sum(["h", 2.5, "e", 3.5])).toEqual(6); +}); // 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 non-number values, returns Not a Number (NaN)", () => { + expect(sum(["a", "b", "c"])).toBeNaN() // note: NaN !== NaN, +}); diff --git a/Sprint-1/refactor/includes.js b/Sprint-1/refactor/includes.js index 29dad81f0..c7e60b831 100644 --- a/Sprint-1/refactor/includes.js +++ b/Sprint-1/refactor/includes.js @@ -1,13 +1,10 @@ // 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]; - if (element === target) { - return true; - } + for (const element of list) { + if (element === target) return true; } return false; } -module.exports = includes; +module.exports = includes; \ No newline at end of file From 5e3891acba1a219c1ac347343a964f441533d072 Mon Sep 17 00:00:00 2001 From: Angela McLeary Date: Sun, 15 Mar 2026 17:51:31 +0000 Subject: [PATCH 8/9] formatted code with prettier --- Sprint-1/fix/median.js | 2 +- Sprint-1/fix/median.test.js | 22 +++++++++++++++++----- Sprint-1/implement/dedupe.js | 6 +++--- Sprint-1/implement/max.js | 2 +- Sprint-1/implement/max.test.js | 2 +- Sprint-1/implement/sum.js | 14 +++++++------- Sprint-1/implement/sum.test.js | 2 +- Sprint-1/refactor/includes.js | 2 +- 8 files changed, 32 insertions(+), 20 deletions(-) diff --git a/Sprint-1/fix/median.js b/Sprint-1/fix/median.js index e83021de7..9d2c75753 100644 --- a/Sprint-1/fix/median.js +++ b/Sprint-1/fix/median.js @@ -22,7 +22,7 @@ function calculateMedian(list) { } return sortedList[middleIndex]; //if it is odd it returns the middle number -} +}; //checking // console.log(calculateMedian([1, 2, "3", null, undefined, 4])); // 2 // console.log(calculateMedian([1, 2, 3, 4])); // 2.5 diff --git a/Sprint-1/fix/median.test.js b/Sprint-1/fix/median.test.js index 21da654d7..c262c3776 100644 --- a/Sprint-1/fix/median.test.js +++ b/Sprint-1/fix/median.test.js @@ -13,7 +13,8 @@ describe("calculateMedian", () => { { input: [1, 2, 3, 4], expected: 2.5 }, { input: [1, 2, 3, 4, 5, 6], expected: 3.5 }, ].forEach(({ input, expected }) => - it(`returns the median for [${input}]`, () => expect(calculateMedian(input)).toEqual(expected)) + it(`returns the median for [${input}]`, () => + expect(calculateMedian(input)).toEqual(expected)) ); [ @@ -24,7 +25,8 @@ describe("calculateMedian", () => { { input: [110, 20, 0], expected: 20 }, { input: [6, -2, 2, 12, 14], expected: 6 }, ].forEach(({ input, expected }) => - it(`returns the correct median for unsorted array [${input}]`, () => expect(calculateMedian(input)).toEqual(expected)) + it(`returns the correct median for unsorted array [${input}]`, () => + expect(calculateMedian(input)).toEqual(expected)) ); it("doesn't modify the input array [3, 1, 2]", () => { @@ -33,8 +35,17 @@ describe("calculateMedian", () => { expect(list).toEqual([3, 1, 2]); }); - [ 'not an array', 123, null, undefined, {}, [], ["apple", null, undefined] ].forEach(val => - it(`returns null for non-numeric array (${val})`, () => expect(calculateMedian(val)).toBe(null)) + [ + "not an array", + 123, + null, + undefined, + {}, + [], + ["apple", null, undefined], + ].forEach((val) => + it(`returns null for non-numeric array (${val})`, () => + expect(calculateMedian(val)).toBe(null)) ); [ @@ -45,6 +56,7 @@ describe("calculateMedian", () => { { input: [3, "apple", 1, null, 2, undefined, 4], expected: 2.5 }, { input: ["banana", 5, 3, "apple", 1, 4, 2], expected: 3 }, ].forEach(({ input, expected }) => - it(`filters out non-numeric values and calculates the median for [${input}]`, () => expect(calculateMedian(input)).toEqual(expected)) + it(`filters out non-numeric values and calculates the median for [${input}]`, () => + expect(calculateMedian(input)).toEqual(expected)) ); }); diff --git a/Sprint-1/implement/dedupe.js b/Sprint-1/implement/dedupe.js index 4eb65e893..a1df68799 100644 --- a/Sprint-1/implement/dedupe.js +++ b/Sprint-1/implement/dedupe.js @@ -2,7 +2,7 @@ function dedupe(arr) { if (arr.length === 0) { //checks if array is empty return arr; - } + }; const newArray = []; // to store the new values after checking and deduplicating for (let i = 0; i < arr.length; i++) { // checks every item in array for dupes @@ -10,9 +10,9 @@ function dedupe(arr) { //checks if new item is already in newArray newArray.push(arr[i]); // adds new item !in newArray and appends it } - } + }; return newArray; // returns new array without duplicates/empty -} +}; console.log(dedupe([])); // prints: [] console.log(dedupe([1, 2, 3])); // prints: [ 1, 2, 3 ] diff --git a/Sprint-1/implement/max.js b/Sprint-1/implement/max.js index 749ac12fa..ff48296aa 100644 --- a/Sprint-1/implement/max.js +++ b/Sprint-1/implement/max.js @@ -2,7 +2,7 @@ function findMax(elements) { if (!Array.isArray(elements)) return null; if (elements.length === 0) return -Infinity; -// must include declaration for infinity or test fails. + // must include declaration for infinity or test fails. const numbers = elements.filter((num) => typeof num === "number"); if (numbers.length === 0) return NaN; // it returns NaN if no numbers found, there is no need to sort the numbers diff --git a/Sprint-1/implement/max.test.js b/Sprint-1/implement/max.test.js index d4af03488..8cab485b2 100644 --- a/Sprint-1/implement/max.test.js +++ b/Sprint-1/implement/max.test.js @@ -17,7 +17,7 @@ const findMax = require("./max.js"); // Then it should return -Infinity // Delete this test.todo and replace it with a test. test("given an empty array, it returns -Infinity", () => { - expect(findMax([])).toBe(-Infinity) + expect(findMax([])).toBe(-Infinity); }); // Given an array with one number diff --git a/Sprint-1/implement/sum.js b/Sprint-1/implement/sum.js index 5860f35ad..f7a2b1ef4 100644 --- a/Sprint-1/implement/sum.js +++ b/Sprint-1/implement/sum.js @@ -6,10 +6,10 @@ function sum(elements) { return numbers.reduce((total, nextNumber) => total + nextNumber, 0); } console.log(sum([])); // 0 -console.log(sum([1]));// 1 -console.log(sum([5, 2, -3]));//4 -console.log(sum([1.5, 2.5, 3.5]));//7.5 -console.log(sum(["h", 2.5, "e", 3.5]));//6 -console.log(sum(["a", "b", "c", "d"]));//Nan -6 -module.exports = sum; \ No newline at end of file +console.log(sum([1])); // 1 +console.log(sum([5, 2, -3])); //4 +console.log(sum([1.5, 2.5, 3.5])); //7.5 +console.log(sum(["h", 2.5, "e", 3.5])); //6 +console.log(sum(["a", "b", "c", "d"])); //Nan + +module.exports = sum; diff --git a/Sprint-1/implement/sum.test.js b/Sprint-1/implement/sum.test.js index cd13f4ae6..ff638c0a5 100644 --- a/Sprint-1/implement/sum.test.js +++ b/Sprint-1/implement/sum.test.js @@ -48,5 +48,5 @@ test("given an array containing non-number values, it should ignore the non-numb // 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 non-number values, returns Not a Number (NaN)", () => { - expect(sum(["a", "b", "c"])).toBeNaN() // note: NaN !== NaN, + expect(sum(["a", "b", "c"])).toBeNaN(); // note: NaN !== NaN, }); diff --git a/Sprint-1/refactor/includes.js b/Sprint-1/refactor/includes.js index c7e60b831..cc167f1bb 100644 --- a/Sprint-1/refactor/includes.js +++ b/Sprint-1/refactor/includes.js @@ -7,4 +7,4 @@ function includes(list, target) { return false; } -module.exports = includes; \ No newline at end of file +module.exports = includes; From 165c3cbeb65d2dc4b93e2d9dd8bcfde49fec80b4 Mon Sep 17 00:00:00 2001 From: Angela McLeary Date: Sat, 28 Mar 2026 15:16:38 +0000 Subject: [PATCH 9/9] updated files after pull request --- Sprint-1/implement/dedupe.test.js | 1 + 1 file changed, 1 insertion(+) diff --git a/Sprint-1/implement/dedupe.test.js b/Sprint-1/implement/dedupe.test.js index 05e4a9a6d..2b51f00c2 100644 --- a/Sprint-1/implement/dedupe.test.js +++ b/Sprint-1/implement/dedupe.test.js @@ -39,3 +39,4 @@ test("given an array with strings or numbers, it removes the duplicates preservi }); // Then it should return a new array with duplicates removed while preserving the // first occurrence of each element from the original array. +// updated version