From fad89474f47c2f05825eafcd9fdc2f2097e91eec Mon Sep 17 00:00:00 2001 From: tasleemadedokun Date: Thu, 19 Mar 2026 05:54:55 +0000 Subject: [PATCH 1/6] Implement new function to pass all test. --- Sprint-1/fix/median.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Sprint-1/fix/median.js b/Sprint-1/fix/median.js index b22590bc6..17865dfac 100644 --- a/Sprint-1/fix/median.js +++ b/Sprint-1/fix/median.js @@ -6,9 +6,15 @@ // 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)) return null; + + const nums = list.filter((n) => typeof n === "number" && !isNaN(n)); + if (!nums.length) return null; + + const sorted = nums.slice().sort((a, b) => a - b); + const mid = Math.floor(sorted.length / 2); + + return sorted.length % 2 ? sorted[mid] : (sorted[mid - 1] + sorted[mid]) / 2; } module.exports = calculateMedian; From da8117a902464e352a49b20f177690cd1038c2df Mon Sep 17 00:00:00 2001 From: tasleemadedokun Date: Thu, 19 Mar 2026 06:06:54 +0000 Subject: [PATCH 2/6] Effect the new function for dedupe. --- Sprint-1/implement/dedupe.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/Sprint-1/implement/dedupe.js b/Sprint-1/implement/dedupe.js index 781e8718a..bfedf4ed4 100644 --- a/Sprint-1/implement/dedupe.js +++ b/Sprint-1/implement/dedupe.js @@ -1 +1,17 @@ -function dedupe() {} +function dedupe(arr) { + if (!Array.isArray(arr)) return []; + + const seen = new Set(); + const result = []; + + for (const item of arr) { + if (!seen.has(item)) { + seen.add(item); + result.push(item); + } + } + + return result; +} + +module.exports = dedupe; From 21c8c5982647fb1f693487e23173601e26e73ae6 Mon Sep 17 00:00:00 2001 From: tasleemadedokun Date: Thu, 19 Mar 2026 06:08:16 +0000 Subject: [PATCH 3/6] i --- Sprint-1/package-lock.json | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Sprint-1/package-lock.json b/Sprint-1/package-lock.json index 83e427d0b..743bde1f7 100644 --- a/Sprint-1/package-lock.json +++ b/Sprint-1/package-lock.json @@ -2125,9 +2125,9 @@ } }, "node_modules/istanbul-lib-instrument/node_modules/semver": { - "version": "7.6.3", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.3.tgz", - "integrity": "sha512-oVekP1cKtI+CTDvHWYFUcMtsK/00wmAEfyqKfNdARm8u1wNVhSgaX7A8d4UuIlUI5e84iEwOhs7ZPYRmzU9U6A==", + "version": "7.7.4", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.7.4.tgz", + "integrity": "sha512-vFKC2IEtQnVhpT78h1Yp8wzwrf8CM+MzKMHGJZfBtzhZNycRFnXsHk6E5TxIkkMsgNS7mdX3AGB7x2QM2di4lA==", "dev": true, "license": "ISC", "bin": { @@ -2664,9 +2664,9 @@ } }, "node_modules/jest-snapshot/node_modules/semver": { - "version": "7.6.3", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.3.tgz", - "integrity": "sha512-oVekP1cKtI+CTDvHWYFUcMtsK/00wmAEfyqKfNdARm8u1wNVhSgaX7A8d4UuIlUI5e84iEwOhs7ZPYRmzU9U6A==", + "version": "7.7.4", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.7.4.tgz", + "integrity": "sha512-vFKC2IEtQnVhpT78h1Yp8wzwrf8CM+MzKMHGJZfBtzhZNycRFnXsHk6E5TxIkkMsgNS7mdX3AGB7x2QM2di4lA==", "dev": true, "license": "ISC", "bin": { @@ -2898,9 +2898,9 @@ } }, "node_modules/make-dir/node_modules/semver": { - "version": "7.6.3", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.3.tgz", - "integrity": "sha512-oVekP1cKtI+CTDvHWYFUcMtsK/00wmAEfyqKfNdARm8u1wNVhSgaX7A8d4UuIlUI5e84iEwOhs7ZPYRmzU9U6A==", + "version": "7.7.4", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.7.4.tgz", + "integrity": "sha512-vFKC2IEtQnVhpT78h1Yp8wzwrf8CM+MzKMHGJZfBtzhZNycRFnXsHk6E5TxIkkMsgNS7mdX3AGB7x2QM2di4lA==", "dev": true, "license": "ISC", "bin": { From e2214bf727ff91fcb811fa800559afd86cbfb4e7 Mon Sep 17 00:00:00 2001 From: tasleemadedokun Date: Fri, 20 Mar 2026 03:12:11 +0000 Subject: [PATCH 4/6] Implement function and test to max.js and max.test.js --- Sprint-1/implement/max.js | 7 +++++++ Sprint-1/implement/max.test.js | 26 +++++++++++++++++++++----- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/Sprint-1/implement/max.js b/Sprint-1/implement/max.js index 6dd76378e..7cdc5c6bd 100644 --- a/Sprint-1/implement/max.js +++ b/Sprint-1/implement/max.js @@ -1,4 +1,11 @@ function findMax(elements) { + if (!Array.isArray(elements)) return -Infinity; + + const nums = elements.filter((n) => typeof n === "number" && !isNaN(n)); + + if (nums.length === 0) return -Infinity; + + return nums.reduce((max, curr) => (curr > max ? curr : max), -Infinity); } module.exports = findMax; diff --git a/Sprint-1/implement/max.test.js b/Sprint-1/implement/max.test.js index 82f18fd88..760bd1fb5 100644 --- a/Sprint-1/implement/max.test.js +++ b/Sprint-1/implement/max.test.js @@ -16,28 +16,44 @@ 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([])).toBe(-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([8])).toBe(8); + }); // Given an array with both positive and negative numbers // When passed to the max function // Then it should return the largest number overall - +test("returns the largest number from positive and negative numbers", () => { + expect(findMax([5, -9, 25, 8, -12])).toBe(25); + }); // Given an array with just negative numbers // When passed to the max function // Then it should return the closest one to zero - +test("returns the closest to zero for all negative numbers", () => { + expect(findMax([-10, -2, -25])).toBe(-2); + }); // Given an array with decimal numbers // When passed to the max function // Then it should return the largest decimal number - +test("returns the largest decimal number", () => { + expect(findMax([1.9, 2.9, 2.5])).toBe(2.9); + }); // 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-numeric values", () => { + expect(findMax(["hey", 10, "hello", 50, 20])).toBe(50); + }); // 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("returns -Infinity for only non-number values", () => { + expect(findMax(["a", null, undefined])).toBe(-Infinity); + }); From b08694ed2e90fd88f51b62b504ebe4c5cf1ec716 Mon Sep 17 00:00:00 2001 From: tasleemadedokun Date: Fri, 20 Mar 2026 03:24:51 +0000 Subject: [PATCH 5/6] Write function implementation for sum.js --- Sprint-1/implement/sum.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Sprint-1/implement/sum.js b/Sprint-1/implement/sum.js index 9062aafe3..10f1fbe0f 100644 --- a/Sprint-1/implement/sum.js +++ b/Sprint-1/implement/sum.js @@ -1,4 +1,15 @@ function sum(elements) { + if (!Array.isArray(elements)) return 0; + + let total = 0; + + for (const item of elements) { + if (typeof item === "number") { + total += item; + } + } + + return total; } module.exports = sum; From 46c0b91be5ae1038bfd091463e3e0cb4012f11d9 Mon Sep 17 00:00:00 2001 From: tasleemadedokun Date: Fri, 20 Mar 2026 03:31:05 +0000 Subject: [PATCH 6/6] Change the if with a for of loop --- 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; }