Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
5decc55
Refactor calculateMedian function to ensure input is an array before …
CatchingKiyoko Jul 4, 2025
5b12f55
Fix calculateMedian function to filter out non-number values from the…
CatchingKiyoko Jul 4, 2025
1c395d6
Fix calculateMedian function to correctly compute the median value fr…
CatchingKiyoko Jul 4, 2025
11a010f
Add check to return null if no valid numbers are present in calculate…
CatchingKiyoko Jul 4, 2025
589fef7
Fix calculateMedian function to ensure sorting occurs before finding …
CatchingKiyoko Jul 4, 2025
fc0d9bc
Refactor includes function to use for...of loop for improved readability
CatchingKiyoko Jul 4, 2025
4199529
implement: initialize newArray ready to store unique values for dedup…
CatchingKiyoko Jul 4, 2025
df0b19c
feat: implement for...of loop to iterate through input array
CatchingKiyoko Jul 4, 2025
a93c361
added check to prevent duplicate values using .includes()
CatchingKiyoko Jul 4, 2025
88ef053
implemented: push non-duplicate items to unique array and return the …
CatchingKiyoko Jul 4, 2025
00abcc4
fix: add missing array parameter to dedupe function
CatchingKiyoko Jul 4, 2025
1e3002d
refactored: removed console.log
CatchingKiyoko Jul 4, 2025
d5cc4cf
reimplmented the module.exports for tests
CatchingKiyoko Jul 4, 2025
5fde149
implemented tests for giving the function an array with no duplicates…
CatchingKiyoko Jul 4, 2025
b07f167
add unit tests for dedupe function to ensure it removes duplicates wh…
CatchingKiyoko Jul 5, 2025
128a345
feat: implement findMax function to filter numbers from an array
CatchingKiyoko Jul 9, 2025
05d5b01
implemented findMax function to return the maximum number from an array
CatchingKiyoko Jul 9, 2025
f630baa
implemented findMax function to return -Infinity when array is empty
CatchingKiyoko Jul 9, 2025
2235414
fix: move empty array check to the correct position in findMax function
CatchingKiyoko Jul 9, 2025
4bcc171
updated test for findMax function when given an empty array
CatchingKiyoko Jul 9, 2025
f84d2f2
added test a array has one number in and returns that number
CatchingKiyoko Jul 9, 2025
e78614b
added jest Test given an array with both positive and negative number…
CatchingKiyoko Jul 9, 2025
ff06a57
added jest Test: given an array with just negative numbers, returns t…
CatchingKiyoko Jul 9, 2025
f0d4e09
added jest Test: given an array with decimal numbers, returns the lar…
CatchingKiyoko Jul 9, 2025
426d205
added jest test: given an array with non-number values, returns the m…
CatchingKiyoko Jul 9, 2025
4221f01
added jest test: given an array with only non-number values, returns …
CatchingKiyoko Jul 9, 2025
b656247
Add check to return 0 if input array is empty in sum function
CatchingKiyoko Jul 12, 2025
5e62085
added jest test for if given an array is empty
CatchingKiyoko Jul 12, 2025
de951df
added for...of loop for to check elements in the arrays are numbers a…
CatchingKiyoko Jul 12, 2025
d87cea0
added jest test for if an array has just one number
CatchingKiyoko Jul 12, 2025
0ab4dfe
added jest tests for if an array contains negative numbers
CatchingKiyoko Jul 12, 2025
93778e0
added jest test for when an array has decima/float numbers
CatchingKiyoko Jul 12, 2025
cabb9a6
added jest test for if an array contains non-numerical values
CatchingKiyoko Jul 12, 2025
da4dd6c
added jest test for when an array has only non-numerical values
CatchingKiyoko Jul 12, 2025
f9e39f9
Merge branch 'CodeYourFuture:main' into Data-Groups-sprint-1
CatchingKiyoko Jul 24, 2025
d34c3d6
Merge branch 'CodeYourFuture:main' into Data-Groups-sprint-1
CatchingKiyoko Oct 25, 2025
f7ce9b8
Merge branch 'CodeYourFuture:main' into Data-Groups-sprint-1
CatchingKiyoko Nov 1, 2025
36aee36
refactor: improve median calculation by filtering non-finite values a…
CatchingKiyoko Nov 22, 2025
37f83e2
Merge branch 'CodeYourFuture:main' into Data-Groups-sprint-1
CatchingKiyoko Nov 22, 2025
b5e6faa
Merge branch 'Data-Groups-sprint-1' of https://github.com/CatchingKiy…
CatchingKiyoko Nov 22, 2025
db5390c
added tests to check if the dedupe function makes an new array and no…
CatchingKiyoko Nov 22, 2025
205ef3d
refactor: improve code readability and formatting in findMax function
CatchingKiyoko Nov 22, 2025
8b4c736
fix: correct assertion method in test for non-numerical values in sum…
CatchingKiyoko Nov 29, 2025
bc910d7
fix: corrected .toBeCloseTo()
CatchingKiyoko Nov 29, 2025
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
28 changes: 24 additions & 4 deletions Sprint-1/fix/median.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,29 @@
// or 'list' has mixed values (the function is expected to sort only numbers).

function calculateMedian(list) {
// checks if "list" is an array if not return's null.
if (!Array.isArray(list)) return null;

// filter the non number values out of an array like "strings", and checks for " Infinte, -Infinte, null's and undefined"
const numbers = list.filter(value => Number.isFinite(value));

// if no numbers are left return null
if (numbers.length === 0) return null;

// sort numbers into ascending order
numbers.sort(function (a, b) {
return a - b;
});

// finds the middle index based on filtered numbers length
const middleIndex = Math.floor(list.length / 2);
const median = list.splice(middleIndex, 1)[0];
return median;
}

module.exports = calculateMedian;
// return the correct median based on if its even or odd
if (numbers.length % 2 === 0) {
// even length average of two middle numbers
return (numbers[middleIndex - 1] + numbers[middleIndex]) / 2;
} else {
// odd length returns the middle number
return numbers[middleIndex];
}
}
18 changes: 17 additions & 1 deletion Sprint-1/implement/dedupe.js
Original file line number Diff line number Diff line change
@@ -1 +1,17 @@
function dedupe() {}
function dedupe(array) {
// makes a new array to store non duplicate values
const newArray = [];

// loops over each item in the original array
for (const item of array) {
// checks if the values are not in the "newArray"
if (!newArray.includes(item)) {
// if item is not in "newArray" adds it to the array
newArray.push(item);
}
}
// returns the new deduped array
return newArray;
}

module.exports = dedupe;
20 changes: 18 additions & 2 deletions Sprint-1/implement/dedupe.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,28 @@ 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, it returns a copy of the original array", () => {
expect(dedupe([1, 2, 3])).toEqual([1, 2, 3]);
expect(dedupe(["a", "b", "c"])).toEqual(["a", "b", "c"]);

const original = [1, 2, 3];
const result = dedupe(original);

expect(result).toEqual(original);
expect(result).not.toBe(original);
});

// 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 duplicates it removes any duplicates and preserves the first instance of each element", () => {
expect(dedupe(["a", "a", "a", "b", "b", "c"])).toEqual(["a", "b", "c"]);
expect(dedupe([5, 1, 1, 2, 3, 2, 5, 8])).toEqual([5, 1, 2, 3, 8]);
expect(dedupe([1, 2, 1])).toEqual([1, 2]);
});
29 changes: 28 additions & 1 deletion Sprint-1/implement/max.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,31 @@
function findMax(elements) {
}
// makes an array to hold only numbers
const numbersOnly = [];

// to loop through each element in the array
for (const item of elements) {
// if the item is a number push it to the numbersOnly array
if (typeof item === `number`) {
numbersOnly.push(item);
}
}
// if the no numbers are found in the array returns -infinty
if (numbersOnly.length === 0) {
return -Infinity;
}

// start with the first number in the "numbersOnly" array
let max = numbersOnly[0];

// loop for the largest number in the "numbersOnly" array
for (const num of numbersOnly) {
if (num > max) {
max = num;
}
}
return max;
}
console.log(findMax([30, 50, 10, 40])); // 50
console.log(findMax(["hey", 10, "hi", 60, 10])); // 60
console.log(findMax([])); // -infinity
module.exports = findMax;
23 changes: 21 additions & 2 deletions Sprint-1/implement/max.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,47 @@ 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 one number", () => {
expect(findMax([42])).toBe(42);
});

// 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 returns the largest", () => {
expect(findMax([-10, 5, -30, 27])).toBe(27);
})

// 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 one to zero", () => {
expect(findMax([-100, -10, -5, -50])).toBe(-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, returns the largest decimal", () => {
expect(findMax([1.5, 2.3, 0.7, ,3.14, 2.71])).toBe(3.14);
});

// 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, returns the max and removes the non-numeric values", () => {
expect(findMax([`hey`, 10, `hi`, 60, 10])).toBe(60);
})

// 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, returns -Infinity", () => {
expect(findMax([`hey`, `hi`, `hello`])).toBe(-Infinity);
})
13 changes: 13 additions & 0 deletions Sprint-1/implement/sum.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
function sum(elements) {
if (elements.length === 0) return 0; // if array is input is empty returns 0

let total = 0; // create a variable to hold the sum

// iterate over each element in the array
for (const value of elements){
// checks if each of the values are numbers
if (typeof value === `number`){
// adds the numbers to the total sum
total += value;
}
}
return total; // returns the total sum after the loop has finished adding all the numbers
}

module.exports = sum;
22 changes: 20 additions & 2 deletions Sprint-1/implement/sum.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,42 @@ 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([])).toBe(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 a single number return that number", () => {
expect(sum([42])).toBe(42);
})

// 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 with negative numbers returns the correct total sum", () => {
expect(sum([-10, -20, -30])).toBe(-60);
expect(sum([-10, 20, -30])).toBe(-20);
});
// 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 numbers in returns the correct total sum", () => {
expect(sum([10.5, 20.2, 30.3])).toBe(61.0);
expect(sum([10.5, -20.2, 30.3])).toBe(20.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
test("given an array containing non-numerical values ignore non-numerical and returns correct total sum", () => {
expect(sum([2, "hello", 26.5, "hey", -6.6, 8])).toBeCloseTo(29.9);
});

// 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-numerical values returns 0", () => {
expect(sum(["a", "b", "c"])).toBe(0);
});
7 changes: 5 additions & 2 deletions Sprint-1/refactor/includes.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
// 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];
// iterate through each element in the list
for (const element of list){

// If an element matches the target, return true
if (element === target) {
return true;
}
}
// If no element matches the target, return false
return false;
}

Expand Down