Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
13fca37
array of numbers fixed
MattCarolus10 Oct 24, 2026
010e59e
non empty array fixed
MattCarolus10 Oct 24, 2026
a885859
non list of array fixed
MattCarolus10 Oct 24, 2026
cd95950
all test function fixed
MattCarolus10 Oct 24, 2026
3cc7cf4
empty array return infinity
MattCarolus10 Oct 24, 2026
79f3284
empty array return infinity
MattCarolus10 Oct 24, 2026
df508f3
test given an array of one number
MattCarolus10 Oct 24, 2026
523c22c
test largest positive and negative numbers
MattCarolus10 Oct 24, 2026
92b41f3
fix: correct syntax in test for largest of positive and negative numbers
MattCarolus10 Oct 24, 2026
55446f7
closest to zero for all negative numbers
MattCarolus10 Oct 24, 2026
59800af
closest to zero for all negative numbers
MattCarolus10 Oct 24, 2026
01356bc
test for largest decimal numbers
MattCarolus10 Oct 24, 2026
8223706
test containing non-numbers
MattCarolus10 Oct 24, 2026
40ab195
test for not given an array
MattCarolus10 Oct 24, 2026
f095dbf
fix not array test
MattCarolus10 Oct 24, 2026
3660134
length equals zero test fix
MattCarolus10 Oct 24, 2026
289a04c
refactor error handling and formatting in findMax function
MattCarolus10 Oct 24, 2026
d70f176
fix: correct case of -Infinity in empty array test
MattCarolus10 Oct 24, 2026
2163cf1
fix: correct case of -Infinity and fix type checks in findMax function
MattCarolus10 Oct 24, 2026
0eb22a9
refactor: remove unnecessary comments and clean up max.test.js
MattCarolus10 Oct 25, 2026
794f3b1
refactor: improve formatting and indentation in max.test.js
MattCarolus10 Oct 25, 2026
8dc93ce
test: implement test case for empty array in sum function
MattCarolus10 Oct 25, 2026
87581d4
test: fix test case for returning a number from an array
MattCarolus10 Oct 25, 2026
6fb4efd
test: fix test case for adding negative numbers in sum function
MattCarolus10 Oct 25, 2026
cf80450
test: add test cases for decimal numbers and non-number inputs in sum…
MattCarolus10 Oct 25, 2026
04f33f8
test: add case to throw error when input is not an array in sum function
MattCarolus10 Oct 25, 2026
14a6f66
fix: correct variable name in array check for sum function
MattCarolus10 Oct 25, 2026
20c90a2
fix: correct variable name in array check for sum function
MattCarolus10 Oct 25, 2026
021392c
fix: correct variable name and implement summation logic in sum function
MattCarolus10 Oct 25, 2026
bca8798
fix: correct formatting in sum function for consistency
MattCarolus10 Oct 25, 2026
9c02fb8
fix: correct syntax errors in sum function tests
MattCarolus10 Oct 25, 2026
718a3b1
fix: correct function calls in sum tests for accuracy
MattCarolus10 Oct 25, 2026
75a3863
fix: rename parameter in sum function for clarity
MattCarolus10 Oct 25, 2026
c555e30
fix: add missing import statement for findMax in max tests
MattCarolus10 Oct 25, 2026
0a8ffc9
fix: remove unnecessary comments and documentation in sum tests for c…
MattCarolus10 Oct 25, 2026
7d531a4
fix: implement test for empty array case in dedupe function
MattCarolus10 Oct 25, 2026
c9a0b25
fix: add test for dedupe function to verify handling of duplicate ele…
MattCarolus10 Oct 25, 2026
b21e531
fix: add test to verify preservation of first occurrence order in ded…
MattCarolus10 Oct 25, 2026
586f2b0
feat: implement dedupe function to remove duplicates from an array
MattCarolus10 Oct 25, 2026
9fe1206
fix: remove unnecessary comments and documentation in dedupe tests fo…
MattCarolus10 Oct 25, 2026
9d715a4
test: implement test for calculateMean function with sample input
MattCarolus10 Oct 25, 2026
320a5fa
test: update calculateMean test case to return correct mean for multi…
MattCarolus10 Oct 25, 2026
d3d9156
test: add case to verify calculateMean returns correct value for sing…
MattCarolus10 Oct 25, 2026
7f9881d
test: add case to verify calculateMean handles negative and decimal n…
MattCarolus10 Oct 25, 2026
9ea6b81
test: add case to verify calculateMean throws error for empty array
MattCarolus10 Oct 25, 2026
58bc16c
test: add cases to verify calculateMean throws errors for invalid inputs
MattCarolus10 Oct 25, 2026
44859cb
test: remove unnecessary comments and documentation from mean test file
MattCarolus10 Oct 25, 2026
c15204d
test: implement input validation for calculateMean function
MattCarolus10 Oct 25, 2026
e94100e
test: add validation for non-empty array in calculateMean function
MattCarolus10 Oct 25, 2026
e912e06
fix: ensure calculateMean validates input as an array of numbers
MattCarolus10 Oct 25, 2026
ab6b5a4
fix: correct error message and test description for non-number array …
MattCarolus10 Oct 25, 2026
88a8db1
fix: correct typo in test for handling negative and decimal numbers
MattCarolus10 Oct 25, 2026
da1d6fd
test: implement test for describeMedian function with valid input
MattCarolus10 Oct 26, 2026
edf099c
test: fix expected output for describeMedian function with valid input
MattCarolus10 Oct 26, 2026
2d2960d
test: add missing test for non-array input in describeMedian function
MattCarolus10 Oct 26, 2026
34a8196
fix: correct error messages in tests for describeMedian function
MattCarolus10 Oct 26, 2026
c60bbdf
feat: implement describeMedian function to calculate and return the m…
MattCarolus10 Oct 26, 2026
783f7e6
fix: correct median test output and remove unnecessary comments
MattCarolus10 Oct 26, 2026
611dd7f
refactor: simplify includes function using for...of loop
MattCarolus10 Oct 26, 2026
9a34fb9
fix: update input values in aoc-2018-day1 dataset for accuracy
MattCarolus10 Oct 27, 2026
7b077cf
feat: implement frequency calculation from input file
MattCarolus10 Oct 27, 2026
ec97a6d
feat: update frequency calculation to handle input parsing and duplic…
MattCarolus10 Oct 27, 2026
8a56804
remove prep from sprint branch
MattCarolus10 Oct 27, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions Sprint-1/fix/median.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
// Fix this implementation
// Start by running the tests for this function
// If you're in the Sprint-1 directory, you can run `npm test -- fix` to run the tests in the fix directory

// Hint: Please consider scenarios when 'list' isn't an array, is empty,
// or contains values that aren't numbers (the function is expected to throw - see the tests).

function calculateMedian(list) {
const middleIndex = Math.floor(list.length / 2);
const median = list.splice(middleIndex, 1)[0];
return median;
if (!Array.isArray(list)) {
throw new Error("calculateMedian requires an array of numbers");
}
if (list.length === 0) {
throw new Error("calculateMedian requires a non-empty array");
}
if (!list.every((item) => typeof item === "number")) {
throw new Error("calculateMedian requires an array of numbers");
}
const sorted = [...list].sort((a, b) => a - b);
const middleIndex = Math.floor(sorted.length / 2);
if (sorted.length % 2 === 0) {
return (sorted[middleIndex - 1] + sorted[middleIndex]) / 2;
}

return sorted[middleIndex];
}

module.exports = calculateMedian;
12 changes: 11 additions & 1 deletion Sprint-1/implement/dedupe.js
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
function dedupe() {}
function dedupe(list) {
const result = [];
for (const item of list) {
if (!result.includes(item)) {
result.push(item);
}
}
return result;
}

module.exports = dedupe;
33 changes: 9 additions & 24 deletions Sprint-1/implement/dedupe.test.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,13 @@
const dedupe = require("./dedupe.js");
/*
Dedupe Array

📖 Dedupe means **deduplicate**
test("given an empty array, it returns an empty array", () => {
expect(dedupe([])).toEqual([]);
});

In this kata, you will need to deduplicate the elements of an array
test("returns a a copy with no duplicates", () => {
expect(dedupe(["a", "a", "a", "b", "b", "c"])).toEqual(["a", "b", "c"]);
});

E.g. dedupe(['a','a','a','b','b','c']) returns ['a','b','c']
E.g. dedupe([5, 1, 1, 2, 3, 2, 5, 8]) returns [5, 1, 2, 3, 8]
E.g. dedupe([1, 2, 1]) returns [1, 2]
*/

// Acceptance Criteria:

// 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");

// Given an array with no duplicates
// When passed to the dedupe function
// Then it should return a copy of the original array

// 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.
test("keeps the first occurrence order", () => {
expect(dedupe([5, 1, 1, 2, 3, 2, 5, 8])).toEqual([5, 1, 2, 3, 8]);
});
9 changes: 8 additions & 1 deletion Sprint-1/implement/describe-median.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ function calculateMedian(list) {
}

// Implement this function. See describe-median.test.js for the acceptance criteria.
function describeMedian(list) {}
function describeMedian(list) {
try {
const median = calculateMedian(list);
return "The median is " + median;
} catch (error) {
return "Could not calculate a median: " + error.message;
}
}

module.exports = describeMedian;
40 changes: 13 additions & 27 deletions Sprint-1/implement/describe-median.test.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,18 @@
/* Describe the median, or explain why there isn't one

calculateMedian is given to you at the top of describe-median.js. It throws
when it can't calculate a median. Don't change it.

Implement describeMedian, which calls calculateMedian and returns a sentence
instead of crashing.

E.g. describeMedian([1, 2, 3]), target output: "The median is 2"
E.g. describeMedian([]), target output: "Could not calculate a median: calculateMedian requires a non-empty array"

You'll need a try/catch block for this. The catch block must use the error's
message, so the caller can see what went wrong.
*/

const describeMedian = require("./describe-median.js");

// Acceptance criteria:

// Given an array of numbers
// When passed to describeMedian
// Then it should return "The median is " followed by the median
// Delete this test.todo and replace it with a test.
test.todo('given [1, 2, 3], returns "The median is 2"');
test('given [1, 2, 3], returns "The median is 2"', () => {
expect(describeMedian([1, 2, 3])).toBe("The median is 2");
});

// Given an empty array
// When passed to describeMedian
// Then it should return "Could not calculate a median: calculateMedian requires a non-empty array"
test("returns a sentence for an empty array", () => {
expect(describeMedian([])).toBe(
"Could not calculate a median: calculateMedian requires a non-empty array"
);
});

// Given something that isn't an array of numbers, e.g. "banana"
// When passed to describeMedian
// Then it should return "Could not calculate a median: calculateMedian requires an array of numbers"
test("return a sentence for a non-array", () => {
expect(describeMedian("banana")).toBe(
"Could not calculate a median: calculateMedian requires an array of numbers"
);
});
19 changes: 19 additions & 0 deletions Sprint-1/implement/max.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
function findMax(elements) {
if (!Array.isArray(elements)) {
throw new Error("findMax requires an array of numbers");
}

if (elements.length === 0) {
return -Infinity;
}

if (!elements.every((item) => typeof item === "number")) {
throw new Error("findMax requires an array of numbers");
}

let max = elements[0];
for (const item of elements) {
if (item > max) {
max = item;
}
}
return max;
}

module.exports = findMax;
72 changes: 31 additions & 41 deletions Sprint-1/implement/max.test.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,33 @@
/* Find the maximum element of an array of numbers

In this kata, you will need to implement a function that find the largest numerical element of an array.

E.g. max([30, 50, 10, 40]), target output: 50
E.g. max(['hey', 10, 'hi', 60, 10]) throws Error("findMax requires an array of numbers") (max can't compare non-numerical elements, so it shouldn't guess)

You should implement this function in max.js, and add tests for it in this file.

We have set things up already so that this file can see your function from the other file.
*/

const findMax = require("./max.js");

// 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");

// Given an array with one number
// When passed to the max function
// Then it should return that number

// 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 just negative numbers
// When passed to the max function
// Then it should return the closest one to zero

// Given an array with decimal numbers
// When passed to the max function
// Then it should return the largest decimal number

// Given an array containing a value that isn't a number
// When passed to the max function
// Then it should throw Error("findMax requires an array of numbers")

// Given something that isn't an array at all, such as "hey", 42 or no argument
// When passed to the max function
// Then it should throw Error("findMax requires an array of numbers")
test("given an empty array, returns -Infinity", () => {
expect(findMax([])).toBe(-Infinity);
});

test("given an array with one number, returns that number", () => {
expect(findMax([7])).toBe(7);
});

test("returns the largest of positive and negative numbers", () => {
expect(findMax([-6, 5, -3, 8])).toBe(8);
});

test("returns the closest to zero for all negatives", () => {
expect(findMax([-9, -2, -6])).toBe(-2);
});

test("returns the largest decimal number", () => {
expect(findMax([1.2, 3.8, 2.6])).toBe(3.8);
});

test("throws for an array containing a non-number", () => {
expect(() => findMax(["hey", 10])).toThrow(
new Error("findMax requires an array of numbers")
);
});

test("throws when not given an array", () => {
expect(() => findMax("hey")).toThrow(
new Error("findMax requires an array of numbers")
);
});
17 changes: 16 additions & 1 deletion Sprint-1/implement/mean.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
function calculateMean(list) {}
function calculateMean(list) {
if (!Array.isArray(list)) {
throw new Error("calculateMean requires an array of numbers");
}
if (list.length === 0) {
throw new Error("calculateMean requires a non-empty array");
}
if (!list.every((item) => typeof item === "number")) {
throw new Error("calculateMean requires an array of numbers");
}
let total = 0;
for (const item of list) {
total += item;
}
return total / list.length;
}

module.exports = calculateMean;
77 changes: 29 additions & 48 deletions Sprint-1/implement/mean.test.js
Original file line number Diff line number Diff line change
@@ -1,50 +1,31 @@
/* Calculate the mean of an array of numbers

In this kata, you will need to implement a function that calculates the mean of an array of numbers.

E.g. calculateMean([1, 2, 6]), target output: 3
E.g. calculateMean([]) throws Error("calculateMean requires a non-empty array")
E.g. calculateMean("banana") throws Error("calculateMean requires an array of numbers")

There is no mean of an empty array, and a string isn't an array of numbers, so
calculateMean should throw rather than return a value. This is the same problem
calculateMedian solves in the prep and in the fix directory.

You should implement this function in mean.js, and add tests for it in this file.

We have set things up already so that this file can see your function from the other file.
*/

const calculateMean = require("./mean.js");

// Acceptance criteria:

// Given an array of numbers
// When passed to calculateMean
// Then it should return their mean
// Delete this test.todo and replace it with a test.
test.todo("given [1, 2, 6], returns 3");

// Given an array with a single number
// When passed to calculateMean
// Then it should return that number

// Given an array containing negative or decimal numbers
// When passed to calculateMean
// Then it should return the correct mean

// Given an empty array
// When passed to calculateMean
// Then it should throw Error("calculateMean requires a non-empty array")

// Given a value that isn't an array, e.g. "banana", 42, null or {}
// When passed to calculateMean
// Then it should throw Error("calculateMean requires an array of numbers")

// Given no argument at all
// When passed to calculateMean
// Then it should throw Error("calculateMean requires an array of numbers")

// Given an array containing a non-number value, e.g. [1, "2", 3]
// When passed to calculateMean
// Then it should throw Error("calculateMean requires an array of numbers")
test("given [1, 2, 6], returns 3", () => {
expect(calculateMean([1, 2, 6])).toBe(3);
});

test("returns the number for a single item array", () => {
expect(calculateMean([8])).toBe(8);
});

test("handles negative and decimal numbers", () => {
expect(calculateMean([-2, 4, 3.5])).toBeCloseTo(1.8333);
});

test("throws for an empty array", () => {
expect(() => calculateMean([])).toThrow(
new Error("calculateMean requires a non-empty array")
);
});

test("throws when not given an array", () => {
expect(() => calculateMean("banana")).toThrow(
new Error("calculateMean requires an array of numbers")
);
});

test("throws for an array containing a non-number", () => {
expect(() => calculateMean([1, "2", 3])).toThrow(
new Error("calculateMean requires an array of numbers")
);
});
13 changes: 12 additions & 1 deletion Sprint-1/implement/sum.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
function sum(elements) {
function sum(list) {
if (!Array.isArray(list)) {
throw new Error("sum requires an array of numbers");
}
if (!list.every((item) => typeof item === "number")) {
throw new Error("sum requires an array of numbers");
}
let total = 0;
for (const item of list) {
total += item;
}
return total;
}

module.exports = sum;
Loading
Loading