Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
ebc242e
created package json
Pirikita Nov 11, 2025
f124113
re wrote code to calculate median and pass all tests
Pirikita Nov 11, 2025
a77feba
wrote code following the guidelines
Pirikita Nov 11, 2025
a2c06e6
installed package and dependencies
Pirikita Nov 11, 2025
2f4b642
code for empty array and 1 number array
Pirikita Nov 11, 2025
179683b
code for non-number values
Pirikita Nov 11, 2025
82b7add
finished code, and cleaned it
Pirikita Nov 11, 2025
c788bfa
wrote test for all test cases
Pirikita Nov 11, 2025
2fc3acf
wrote code as indicated in the guidelines
Pirikita Nov 11, 2025
e0ab91c
created test cases
Pirikita Nov 11, 2025
387af8f
rewrote the code using for... of
Pirikita Nov 11, 2025
b1d73db
small visual changes, nothing on code
Pirikita Nov 11, 2025
8c8095c
wrote code to transform input to array
Pirikita Nov 12, 2025
8af33c9
wrote the code to both exercises
Pirikita Nov 12, 2025
80b688b
added package.json
Pirikita Nov 12, 2025
a53cf70
wrote my prevision of what will happen before correcting the code
Pirikita Nov 12, 2025
c3ee6b9
corrected the code in order to work
Pirikita Nov 12, 2025
c1c4007
When fixing the code to make it work, changed the
Pirikita Nov 12, 2025
6e8d07f
console.log all options
Pirikita Nov 12, 2025
71e3a41
predicted what is going to happen and why
Pirikita Nov 13, 2025
d86785f
-Fixed the original code and left comments
Pirikita Nov 13, 2025
193f8bf
Predicted the issue and explained why
Pirikita Nov 13, 2025
5d002d5
- fixed code in order to follow the exercise guidelines
Pirikita Nov 13, 2025
2e54027
- implemented function that checks if an object contains
Pirikita Nov 13, 2025
45cff67
installed json to run tests
Pirikita Nov 13, 2025
7af1316
wrote test cases for all accepted criteria
Pirikita Nov 13, 2025
9783c03
wrote function according to guidelines
Pirikita Nov 13, 2025
6fd9186
wrote test case
Pirikita Nov 13, 2025
e4f7ebd
- Fixed the code with the help of reading materials
Pirikita Nov 18, 2025
1dbd8cd
- tested the original code to check if working;
Pirikita Nov 18, 2025
0c5b96a
Code to check if it's an array
Pirikita Nov 18, 2025
5ea87b7
code for duplicate items
Pirikita Nov 18, 2025
8b4e48f
update the return of an empty array from [] to {}
Pirikita Nov 18, 2025
d3f9f61
created tests for every test case
Pirikita Nov 18, 2025
e90d5de
answer all the questions before fixing the code
Pirikita Nov 19, 2025
b3f840e
fixed the code on line 13
Pirikita Nov 19, 2025
45286cf
prepared doc for export to do test
Pirikita Nov 19, 2025
c69cc00
update the export
Pirikita Nov 19, 2025
156964d
wrote test case for simple key-values, mixed types,
Pirikita Nov 19, 2025
ba6748a
created working function with the exercise basic request
Pirikita Nov 19, 2025
91865cc
finished code and implemented code for advanced challenges
Pirikita Nov 19, 2025
d7401d2
with help of reading materials and AI, understood
Pirikita Nov 19, 2025
a49428d
node test 5 different inputs to check workability
Pirikita Nov 19, 2025
02c9fa6
answer all the questions before fixing the code
Pirikita Nov 20, 2025
233408f
created file for tests
Pirikita Nov 20, 2025
c271021
fixed the code with help of reading materials and AI
Pirikita Nov 20, 2025
371c1e0
wrote case tests
Pirikita Nov 20, 2025
9f73f51
implemented function to delete all completed tasks
Pirikita Nov 28, 2025
ce74ca4
changed the appeared of some features
Pirikita Dec 7, 2025
71d23ba
created code for alarmclock app.
Pirikita Dec 7, 2025
46b4f41
fixed bugs
Pirikita Dec 7, 2025
50ef9d4
fixed code to only change the background color when the input is 10.
Pirikita Dec 7, 2025
0cbc77e
retouch css file
Pirikita Dec 7, 2025
553ea45
update comments on js file
Pirikita Dec 7, 2025
7d59370
initial css styling
Pirikita Dec 7, 2025
a611c02
fixed function bugs
Pirikita Dec 7, 2025
176543b
developed code for reading list
Pirikita Dec 8, 2025
4e9c8d7
fixed last bugs
Pirikita Dec 8, 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
25 changes: 22 additions & 3 deletions Sprint-1/fix/median.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,28 @@
// 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;
// check if its array and if has content
if (!Array.isArray(list) || list.length === 0) return null;

// filter for valid numbers
const numbers = list.filter(
(item) => typeof item === "number" && !isNaN(item)
);

// if there's no numbers returns null
if (numbers.length === 0) return null;

// sort without modifying the original
const sorted = [...numbers].sort((a, b) => a - b);

// calculates median
const middle = Math.floor(sorted.length / 2);

if (sorted.length % 2 === 0) {
return (sorted[middle - 1] + sorted[middle]) / 2;
} else {
return sorted[middle];
}
}

module.exports = calculateMedian;
18 changes: 18 additions & 0 deletions Sprint-1/fix/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "fix",
"version": "1.0.0",
"description": "",
"main": "median.js",
"scripts": {
"test": "jest"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"test": "^3.3.0"
},
"devDependencies": {
"jest": "^30.2.0"
}
}
28 changes: 27 additions & 1 deletion Sprint-1/implement/dedupe.js
Original file line number Diff line number Diff line change
@@ -1 +1,27 @@
function dedupe() {}
function dedupe(arr) {
if (!Array.isArray(arr) || arr.length === 0){
return [];
}
const unique = [...new Set(arr)];
return unique;
}

console.log(dedupe([])); // []
console.log(dedupe([1, 2, 3])); // [1, 2, 3]
console.log(dedupe([1, 2, 2, 3, 1])); // [1, 2, 3]
console.log(dedupe(["apple", "banana", "apple", "orange"])); // ["apple", "banana", "orange"]
console.log(dedupe(["apple", 3, 5, 5, 9, 7, "banana", "orange", "orange"])); // ["apple", 3, 5, 9, 7, "banana", "orange"]

/*Given an empty array
When passed to the dedupe function
Then it should return 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 with strings or numbers
When passed to the dedupe function
Then it should remove the duplicate values, preserving the first occurence of each element*/

module.exports = dedupe;
16 changes: 13 additions & 3 deletions Sprint-1/implement/dedupe.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const dedupe = require("./dedupe.js");

/*
Dedupe Array

Expand All @@ -16,12 +17,21 @@ 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.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 without duplicates, return the copy of original", () => {
expect(dedupe([1, 2, 5, 7, 9])).toEqual([1, 2, 5, 7, 9]);
})
// 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
// Then it should remove the duplicate values, preserving the first occurrence of each element
test("given an array with strings or numbers, return the original without the repeated values", () => {
expect(dedupe(["apple", "apple", "pear", 2, 6, 6, 10, 11, 11, "banana"])).toEqual(["apple", "pear", 2, 6, 10, 11, "banana"]);
})
18 changes: 18 additions & 0 deletions Sprint-1/implement/max.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
function findMax(elements) {
const onlyNumbers = elements.filter(x => typeof x === "number" && !isNaN(x));
// empty array
if ( onlyNumbers.length === 0){
return -Infinity;
// array with only one number
} if ( onlyNumbers.length === 1) {
return onlyNumbers[0];
}
return Math.max(...onlyNumbers);
}

console.log(findMax(["banana", 3, 20, -5, "apple", 3.5]));
console.log(findMax([10, -5, 20, -3])); // 20 (mixed positive/negative)
console.log(findMax([-10, -5, -3, -8])); // -3 (all negative)
console.log(findMax([1.5, 2.8, 1.2, 3.1])); // 3.1 (decimals)
console.log(findMax([233])); // 233 (single number)
console.log(findMax([])); // -Infinity (empty array)
console.log(findMax(["banana"])); // -Infinity (no valid numbers)


module.exports = findMax;
23 changes: 22 additions & 1 deletion Sprint-1/implement/max.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,49 @@ 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.todo("given an empty array, returns -Infinity");
test("given an empty array, returns -Infitiny", () => {
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, 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 both positive and negative numbers, return the largest number overall", () => {
expect(findMax([-10, 3, 6, -1])).toEqual(6);
})

// 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, return the closest one to zero", () => {
expect(findMax([-10, -1, -4, -15])).toEqual(-1);
})

// 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, return the largest decimal number", () => {
expect(findMax([3.2, 4.9, 6.1, 2.9])).toEqual(6.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
test("given an array with non-number values, return the max and ignore non-numeric values", () => {
expect(findMax(["banana", 20, 5, "apple"])).toEqual(20);
})

// 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, return -Infinity", () => {
expect(findMax(["banana", "apple", "orange"])).toEqual(-Infinity);
})
15 changes: 15 additions & 0 deletions Sprint-1/implement/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "implement",
"version": "1.0.0",
"description": "",
"main": "dedupe.js",
"scripts": {
"test": "jest"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"jest": "^30.2.0"
}
}
19 changes: 19 additions & 0 deletions Sprint-1/implement/sum.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
function sum(elements) {
// filter out only valid numbers from the input array
const onlyNumbers = elements.filter(x => typeof x === "number" && !isNaN(x));
// empty array
if ( onlyNumbers.length === 0) {
return 0;
// array with only one number
} if ( onlyNumbers.length === 1) {
return onlyNumbers[0];
} // take first element + sum of the rest untill it's just a number
return onlyNumbers[0] + sum(onlyNumbers.slice(1));
}

console.log(sum([-1, 5, 10, -1]));
console.log(sum(["banana", -1, 5, 10, -1, "pear"]));
console.log(sum([-1, -5, -10, -1]));
console.log(sum([1, 5, 10, 1]));
console.log(sum([]));
console.log(sum([10]));
console.log(sum(["banana"]));
console.log(sum([-1, 5.9, 10.4, -1.2]));

module.exports = sum;
22 changes: 19 additions & 3 deletions Sprint-1/implement/sum.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.todo("given an empty array, returns 0")
test("given an empty array, return 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, return that number", () => {
expect(sum([5])).toEqual(5);
})

// 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, return the correct total sum", () => {
expect(sum([5, -10])).toEqual(-5);
})
// 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, return the correct total sum", () => {
expect(sum([10.1, 10.2, 6.3])).toEqual(26.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-number values, return the sum of numerical elements", () => {
expect(sum(["banana", 5, "apple", 10])).toEqual(15);
})

// 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-number values, return lest surprising value, so 0", () => {
expect(sum(["banana", "apple"])).toEqual(0);
})
14 changes: 12 additions & 2 deletions Sprint-1/refactor/includes.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
// 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;
}
}
return false;
}

console.log(includes([1, 10, 15, 20], 6));
module.exports = includes;

/*function includes(list, target) {
for (let index = 0; index < list.length; index++) {
const element = list[index];
if (element === target) {
return true;
}
}
return false;
}*/
15 changes: 15 additions & 0 deletions Sprint-1/refactor/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "refactor",
"version": "1.0.0",
"description": "",
"main": "includes.js",
"scripts": {
"test": "jest"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"jest": "^30.2.0"
}
}
Loading