From 8c332a3f6f802da37e647df108b0078bf11df79c Mon Sep 17 00:00:00 2001 From: Alex Jamshidi Date: Tue, 12 May 2026 16:25:51 +0100 Subject: [PATCH 1/8] added solution to median.js --- Sprint-1/fix/median.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Sprint-1/fix/median.js b/Sprint-1/fix/median.js index b22590bc6..98c165cce 100644 --- a/Sprint-1/fix/median.js +++ b/Sprint-1/fix/median.js @@ -6,9 +6,13 @@ // 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;} + let numberArray = list.filter(n => Number.isFinite(n)) + if (numberArray.length == 0) {return null}; + numberArray.sort((a, b) => a - b) + + if (numberArray.length % 2 == 1) {return numberArray[((numberArray.length - 1) / 2)]} + else {return (numberArray[((numberArray.length / 2))] + numberArray[((numberArray.length / 2) - 1)]) / 2} } module.exports = calculateMedian; From 5ae1e952db66f35af91e0bdb313d8a9def4dc96b Mon Sep 17 00:00:00 2001 From: Alex Jamshidi Date: Tue, 12 May 2026 22:43:19 +0100 Subject: [PATCH 2/8] added tests for implement dedupe --- Sprint-1/implement/dedupe.js | 6 +++++- Sprint-1/implement/dedupe.test.js | 28 +++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/Sprint-1/implement/dedupe.js b/Sprint-1/implement/dedupe.js index 781e8718a..bf8a5866c 100644 --- a/Sprint-1/implement/dedupe.js +++ b/Sprint-1/implement/dedupe.js @@ -1 +1,5 @@ -function dedupe() {} +function dedupe(array) { + return [1, 2, 3] +} + +module.exports = dedupe; \ No newline at end of file diff --git a/Sprint-1/implement/dedupe.test.js b/Sprint-1/implement/dedupe.test.js index d7c8e3d8e..acc42cc42 100644 --- a/Sprint-1/implement/dedupe.test.js +++ b/Sprint-1/implement/dedupe.test.js @@ -16,13 +16,39 @@ E.g. dedupe([1, 2, 1]) returns [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"); +describe("dedupe", () => { + [ + { input: [], expected: [] }, + ].forEach(({ input, expected }) => + it(`returns empty array for [${input}]`, () => expect(dedupe(input)).toEqual(expected)) + ); + // Given an array with no duplicates // When passed to the dedupe function // Then it should return a copy of the original array + [ + { input: [1, 2, 3], expected: [1, 2, 3] }, + { input: [3, 2, 1, 4, 5], expected: [3, 2, 1, 4, 5] }, + { input: ["hello", "a", "b", "c"], expected: ["hello", "a", "b", "c"] }, + { input: [1, 2, "hello", 4, "a", 6], expected: [1, 2, "hello", 4, "a", 6] }, + ].forEach(({ input, expected }) => + it(`returns the median for [${input}]`, () => expect(dedupe(input)).toEqual(expected)) + ); + // Given an array of strings or numbers // When passed to the dedupe function // Then it should return a new array with duplicates removed while preserving the // first occurrence of each element from the original array. + + [ + { input: [1, 1, 2, 2, 3, 3,], expected: [1, 2, 3] }, + { input: ["a", "a", "b", "b", "c", "c"], expected: ["a", "b", "c"] }, + { input: ["qwe", "qwe", 3, 3, "hello", "hello" , "hello"], expected: ["qwe", 3, "hello"] }, + { input: ["a", "a", "a", "a"], expected: ["a"] }, + { input: [1, 2, 2, 2, 2, 2], expected: [1, 2] }, + ].forEach(({ input, expected }) => + it(`returns the median for [${input}]`, () => expect(dedupe(input)).toEqual(expected)) + ); +}); \ No newline at end of file From 81f05967ea0e838294e32169af57f1946117ae0b Mon Sep 17 00:00:00 2001 From: Alex Jamshidi Date: Tue, 12 May 2026 22:51:00 +0100 Subject: [PATCH 3/8] added solution to implement dedupe --- Sprint-1/implement/dedupe.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Sprint-1/implement/dedupe.js b/Sprint-1/implement/dedupe.js index bf8a5866c..b4b3d6142 100644 --- a/Sprint-1/implement/dedupe.js +++ b/Sprint-1/implement/dedupe.js @@ -1,5 +1,11 @@ function dedupe(array) { - return [1, 2, 3] + const unique = []; + array.forEach((item) => { + if (!unique.includes(item)) { + unique.push(item); + } + }); + return unique } module.exports = dedupe; \ No newline at end of file From 0d3fb031f89a495fa7e359980c0680c55f96b1d8 Mon Sep 17 00:00:00 2001 From: Alex Jamshidi Date: Tue, 12 May 2026 23:20:25 +0100 Subject: [PATCH 4/8] added solutions to max.js --- Sprint-1/implement/max.js | 5 +++- Sprint-1/implement/max.test.js | 42 +++++++++++++++++++++++++++++++++- 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/Sprint-1/implement/max.js b/Sprint-1/implement/max.js index 6dd76378e..77a27adb0 100644 --- a/Sprint-1/implement/max.js +++ b/Sprint-1/implement/max.js @@ -1,4 +1,7 @@ -function findMax(elements) { +function findMax(list) { + const numbers = list.filter(n => Number.isFinite(n)); + if (numbers.length == 0) { return "-Infinity"} + else {return Math.max(...numbers)}; } module.exports = findMax; diff --git a/Sprint-1/implement/max.test.js b/Sprint-1/implement/max.test.js index 82f18fd88..abc39b2f8 100644 --- a/Sprint-1/implement/max.test.js +++ b/Sprint-1/implement/max.test.js @@ -12,32 +12,72 @@ We have set things up already so that this file can see your function from the o const findMax = require("./max.js"); +describe("calculateMedian", () => { // Given an empty array // 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"); + + it("empty array returns -Infinity", () => { + const list = []; + expect(findMax(list)).toEqual("-Infinity"); + }); // Given an array with one number // When passed to the max function // Then it should return that number + it("array with one number returns that number", () => { + const list = [2]; + expect(findMax(list)).toEqual(2); + }); + // Given an array with both positive and negative numbers // When passed to the max function // Then it should return the largest number overall + it("array with +ve and -ve numbers, returns largest number overall", () => { + const list = [10, -15]; + expect(findMax(list)).toEqual(10); + }); + + // Given an array with just negative numbers // When passed to the max function // Then it should return the closest one to zero + it("array -ve numbers, returns closest to zero", () => { + const list = [-1, -2, -3, -15]; + expect(findMax(list)).toEqual(-1); + }); + + // Given an array with decimal numbers // When passed to the max function // Then it should return the largest decimal number + it("array with decimal numbers should return largest decimal number", () => { + const list = [1.9, 2.8999, 3.1]; + expect(findMax(list)).toEqual(3.1); + }); + + // Given an array with non-number values // When passed to the max function // Then it should return the max and ignore non-numeric values + it("array with non-number values, returns the max and ignore non-numeric values", () => { + const list = [1, "a", 2, "b", 3, "c"]; + expect(findMax(list)).toEqual(3); + }); + + // 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 + + it("array with only non-number values, return the least surprising value given how it behaves for all other inputs", () => { + const list = ["a", "b", "c"]; + expect(findMax(list)).toEqual("-Infinity"); + }); +}); \ No newline at end of file From 357426d3ad6f3d7c4c8014eca21420268a7e5b2a Mon Sep 17 00:00:00 2001 From: Alex Jamshidi Date: Tue, 12 May 2026 23:29:03 +0100 Subject: [PATCH 5/8] tests added for sum.test.js in implement --- Sprint-1/implement/sum.js | 3 ++- Sprint-1/implement/sum.test.js | 31 ++++++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/Sprint-1/implement/sum.js b/Sprint-1/implement/sum.js index 9062aafe3..1f8d19de6 100644 --- a/Sprint-1/implement/sum.js +++ b/Sprint-1/implement/sum.js @@ -1,4 +1,5 @@ -function sum(elements) { +function sum(list) { + return 0 } module.exports = sum; diff --git a/Sprint-1/implement/sum.test.js b/Sprint-1/implement/sum.test.js index dd0a090ca..d16782e64 100644 --- a/Sprint-1/implement/sum.test.js +++ b/Sprint-1/implement/sum.test.js @@ -10,27 +10,56 @@ const sum = require("./sum.js"); // Acceptance Criteria: +describe("sum", () => { // Given an empty array // When passed to the sum function // Then it should return 0 -test.todo("given an empty array, returns 0") + it("empty array returns 0", () => { + const list = []; + expect(sum(list)).toEqual(0); + }); // Given an array with just one number // When passed to the sum function // Then it should return that number + it("array with one number returns number", () => { + const list = [1]; + expect(sum(list)).toEqual(1); + }); // Given an array containing negative numbers // When passed to the sum function // Then it should still return the correct total sum + it("array with negative numbers returns correct sum", () => { + const list = [-1, -2, -3]; + expect(sum(list)).toEqual(-6); + }); + // Given an array with decimal/float numbers // When passed to the sum function // Then it should return the correct total sum + it("array with decimal numbers returns correct sum", () => { + const list = [1.1, 2.2, 3.3]; + expect(sum(list)).toEqual(6.6); + }); + // 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 + it("array with non-number values returns sum of numerical values only", () => { + const list = [1]; + expect(sum(list)).toEqual(1); + }); + // 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 + + it("array with non-number values only returns least surprising output", () => { + const list = [1]; + expect(sum(list)).toEqual(0); + }); +}); \ No newline at end of file From ee7e6d499dcd6209ad2cf79fb61dd3caaeb2ecf6 Mon Sep 17 00:00:00 2001 From: Alex Jamshidi Date: Tue, 12 May 2026 23:34:46 +0100 Subject: [PATCH 6/8] added solutions to sum.js in implement --- Sprint-1/implement/sum.js | 5 ++++- Sprint-1/implement/sum.test.js | 6 +++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Sprint-1/implement/sum.js b/Sprint-1/implement/sum.js index 1f8d19de6..5c909fc91 100644 --- a/Sprint-1/implement/sum.js +++ b/Sprint-1/implement/sum.js @@ -1,5 +1,8 @@ function sum(list) { - return 0 + const numbers = list.filter(n => Number.isFinite(n)); + let total = 0; + for (n of numbers) {total += n}; + return total; } module.exports = sum; diff --git a/Sprint-1/implement/sum.test.js b/Sprint-1/implement/sum.test.js index d16782e64..806b8695d 100644 --- a/Sprint-1/implement/sum.test.js +++ b/Sprint-1/implement/sum.test.js @@ -50,8 +50,8 @@ describe("sum", () => { // Then it should ignore the non-numerical values and return the sum of the numerical elements it("array with non-number values returns sum of numerical values only", () => { - const list = [1]; - expect(sum(list)).toEqual(1); + const list = [1, 2, "apple", 4, "banana", 3]; + expect(sum(list)).toEqual(10); }); // Given an array with only non-number values @@ -59,7 +59,7 @@ describe("sum", () => { // Then it should return the least surprising value given how it behaves for all other inputs it("array with non-number values only returns least surprising output", () => { - const list = [1]; + const list = ["a", "b", "c"]; expect(sum(list)).toEqual(0); }); }); \ No newline at end of file From 4e0a556f0b913b6a148ff1ada875ec9519194c59 Mon Sep 17 00:00:00 2001 From: Alex Jamshidi Date: Tue, 12 May 2026 23:44:48 +0100 Subject: [PATCH 7/8] changed includes.js code to add for...of loop --- Sprint-1/refactor/includes.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Sprint-1/refactor/includes.js b/Sprint-1/refactor/includes.js index 29dad81f0..b779c8586 100644 --- a/Sprint-1/refactor/includes.js +++ b/Sprint-1/refactor/includes.js @@ -1,6 +1,15 @@ // Refactor the implementation of includes to use a for...of loop function includes(list, target) { +for (item of list) {if (item === target) {return true;}} + return false; +} + +module.exports = includes; + + +/* Old code: + for (let index = 0; index < list.length; index++) { const element = list[index]; if (element === target) { @@ -8,6 +17,4 @@ function includes(list, target) { } } return false; -} - -module.exports = includes; +*/ From 350ad2e7bcd160db0b206495fe8ba3fa5824baef Mon Sep 17 00:00:00 2001 From: Alex Jamshidi Date: Wed, 13 May 2026 16:53:14 +0100 Subject: [PATCH 8/8] code formatter with prettier --- Sprint-1/fix/median.js | 23 ++++++++++++---- Sprint-1/fix/median.test.js | 22 +++++++++++---- Sprint-1/implement/dedupe.js | 16 +++++------ Sprint-1/implement/max.js | 9 ++++-- Sprint-1/implement/max.test.js | 50 ++++++++++++++++------------------ Sprint-1/implement/sum.js | 10 ++++--- Sprint-1/implement/sum.test.js | 38 +++++++++++++------------- Sprint-1/refactor/includes.js | 9 ++++-- 8 files changed, 102 insertions(+), 75 deletions(-) diff --git a/Sprint-1/fix/median.js b/Sprint-1/fix/median.js index 98c165cce..1f42edab0 100644 --- a/Sprint-1/fix/median.js +++ b/Sprint-1/fix/median.js @@ -6,13 +6,24 @@ // or 'list' has mixed values (the function is expected to sort only numbers). function calculateMedian(list) { - if (!Array.isArray(list)) {return null;} - let numberArray = list.filter(n => Number.isFinite(n)) - if (numberArray.length == 0) {return null}; - numberArray.sort((a, b) => a - b) + if (!Array.isArray(list)) { + return null; + } + let numberArray = list.filter((n) => Number.isFinite(n)); + if (numberArray.length == 0) { + return null; + } + numberArray.sort((a, b) => a - b); - if (numberArray.length % 2 == 1) {return numberArray[((numberArray.length - 1) / 2)]} - else {return (numberArray[((numberArray.length / 2))] + numberArray[((numberArray.length / 2) - 1)]) / 2} + if (numberArray.length % 2 == 1) { + return numberArray[(numberArray.length - 1) / 2]; + } else { + return ( + (numberArray[numberArray.length / 2] + + numberArray[numberArray.length / 2 - 1]) / + 2 + ); + } } module.exports = calculateMedian; 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 b4b3d6142..4ead32366 100644 --- a/Sprint-1/implement/dedupe.js +++ b/Sprint-1/implement/dedupe.js @@ -1,11 +1,11 @@ function dedupe(array) { - const unique = []; - array.forEach((item) => { - if (!unique.includes(item)) { - unique.push(item); - } - }); - return unique + const unique = []; + array.forEach((item) => { + if (!unique.includes(item)) { + unique.push(item); + } + }); + return unique; } -module.exports = dedupe; \ No newline at end of file +module.exports = dedupe; diff --git a/Sprint-1/implement/max.js b/Sprint-1/implement/max.js index 77a27adb0..5c779794e 100644 --- a/Sprint-1/implement/max.js +++ b/Sprint-1/implement/max.js @@ -1,7 +1,10 @@ function findMax(list) { - const numbers = list.filter(n => Number.isFinite(n)); - if (numbers.length == 0) { return "-Infinity"} - else {return Math.max(...numbers)}; + const numbers = list.filter((n) => Number.isFinite(n)); + if (numbers.length == 0) { + return "-Infinity"; + } else { + return Math.max(...numbers); + } } module.exports = findMax; diff --git a/Sprint-1/implement/max.test.js b/Sprint-1/implement/max.test.js index abc39b2f8..6db256392 100644 --- a/Sprint-1/implement/max.test.js +++ b/Sprint-1/implement/max.test.js @@ -13,71 +13,67 @@ We have set things up already so that this file can see your function from the o const findMax = require("./max.js"); describe("calculateMedian", () => { -// Given an empty array -// When passed to the max function -// Then it should return -Infinity -// Delete this test.todo and replace it with a test. + // Given an empty array + // When passed to the max function + // Then it should return -Infinity + // Delete this test.todo and replace it with a test. it("empty array returns -Infinity", () => { const list = []; expect(findMax(list)).toEqual("-Infinity"); }); -// Given an array with one number -// When passed to the max function -// Then it should return that number + // Given an array with one number + // When passed to the max function + // Then it should return that number it("array with one number returns that number", () => { const list = [2]; expect(findMax(list)).toEqual(2); }); -// Given an array with both positive and negative numbers -// When passed to the max function -// Then it should return the largest number overall + // Given an array with both positive and negative numbers + // When passed to the max function + // Then it should return the largest number overall it("array with +ve and -ve numbers, returns largest number overall", () => { const list = [10, -15]; expect(findMax(list)).toEqual(10); }); - -// Given an array with just negative numbers -// When passed to the max function -// Then it should return the closest one to zero + // Given an array with just negative numbers + // When passed to the max function + // Then it should return the closest one to zero it("array -ve numbers, returns closest to zero", () => { const list = [-1, -2, -3, -15]; expect(findMax(list)).toEqual(-1); }); - -// Given an array with decimal numbers -// When passed to the max function -// Then it should return the largest decimal number + // Given an array with decimal numbers + // When passed to the max function + // Then it should return the largest decimal number it("array with decimal numbers should return largest decimal number", () => { const list = [1.9, 2.8999, 3.1]; expect(findMax(list)).toEqual(3.1); }); - -// Given an array with non-number values -// When passed to the max function -// Then it should return the max and ignore non-numeric values + // Given an array with non-number values + // When passed to the max function + // Then it should return the max and ignore non-numeric values it("array with non-number values, returns the max and ignore non-numeric values", () => { const list = [1, "a", 2, "b", 3, "c"]; expect(findMax(list)).toEqual(3); }); - -// 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 + // 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 it("array with only non-number values, return the least surprising value given how it behaves for all other inputs", () => { const list = ["a", "b", "c"]; expect(findMax(list)).toEqual("-Infinity"); }); -}); \ No newline at end of file +}); diff --git a/Sprint-1/implement/sum.js b/Sprint-1/implement/sum.js index 5c909fc91..249515398 100644 --- a/Sprint-1/implement/sum.js +++ b/Sprint-1/implement/sum.js @@ -1,8 +1,10 @@ function sum(list) { - const numbers = list.filter(n => Number.isFinite(n)); - let total = 0; - for (n of numbers) {total += n}; - return total; + const numbers = list.filter((n) => Number.isFinite(n)); + let total = 0; + for (n of numbers) { + total += n; + } + return total; } module.exports = sum; diff --git a/Sprint-1/implement/sum.test.js b/Sprint-1/implement/sum.test.js index 806b8695d..832e11353 100644 --- a/Sprint-1/implement/sum.test.js +++ b/Sprint-1/implement/sum.test.js @@ -11,55 +11,55 @@ const sum = require("./sum.js"); // Acceptance Criteria: describe("sum", () => { -// Given an empty array -// When passed to the sum function -// Then it should return 0 + // Given an empty array + // When passed to the sum function + // Then it should return 0 it("empty array returns 0", () => { const list = []; expect(sum(list)).toEqual(0); }); -// Given an array with just one number -// When passed to the sum function -// Then it should return that number + // Given an array with just one number + // When passed to the sum function + // Then it should return that number it("array with one number returns number", () => { const list = [1]; expect(sum(list)).toEqual(1); }); -// Given an array containing negative numbers -// When passed to the sum function -// Then it should still return the correct total sum + // Given an array containing negative numbers + // When passed to the sum function + // Then it should still return the correct total sum it("array with negative numbers returns correct sum", () => { const list = [-1, -2, -3]; expect(sum(list)).toEqual(-6); }); -// Given an array with decimal/float numbers -// When passed to the sum function -// Then it should return the correct total sum + // Given an array with decimal/float numbers + // When passed to the sum function + // Then it should return the correct total sum it("array with decimal numbers returns correct sum", () => { const list = [1.1, 2.2, 3.3]; expect(sum(list)).toEqual(6.6); }); -// 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 + // 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 it("array with non-number values returns sum of numerical values only", () => { const list = [1, 2, "apple", 4, "banana", 3]; expect(sum(list)).toEqual(10); }); -// 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 + // 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 it("array with non-number values only returns least surprising output", () => { const list = ["a", "b", "c"]; expect(sum(list)).toEqual(0); }); -}); \ No newline at end of file +}); diff --git a/Sprint-1/refactor/includes.js b/Sprint-1/refactor/includes.js index b779c8586..c5b01e86c 100644 --- a/Sprint-1/refactor/includes.js +++ b/Sprint-1/refactor/includes.js @@ -1,13 +1,16 @@ // Refactor the implementation of includes to use a for...of loop function includes(list, target) { -for (item of list) {if (item === target) {return true;}} - return false; + for (item of list) { + if (item === target) { + return true; + } + } + return false; } module.exports = includes; - /* Old code: for (let index = 0; index < list.length; index++) {