Skip to content

Commit 2c6f358

Browse files
committed
Remove legacy tasks from the old js2 module and add correct ones
1 parent b92f9e4 commit 2c6f358

File tree

149 files changed

+1880
-3574
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

149 files changed

+1880
-3574
lines changed

Sprint-1/fix/median.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Fix this implementation
2+
// Start by running the tests for this function
3+
// If you're in the week-1 directory, you can run npm test -- fix to run the tests in the fix directory
4+
5+
function calculateMedian(list) {
6+
const middleIndex = Math.floor(list.length / 2);
7+
const median = list.splice(middleIndex, 1)[0];
8+
return median;
9+
}
10+
11+
module.exports = calculateMedian;

Sprint-1/fix/median.test.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// median.test.js
2+
3+
// Someone has implemented calculateMedian but it isn't
4+
// passing all the tests...
5+
// Fix the implementation of calculateMedian so it passes all tests
6+
7+
const calculateMedian = require("./median.js");
8+
9+
describe("calculateMedian", () => {
10+
test("returns the median for odd length array", () => {
11+
expect(calculateMedian([1, 2, 3])).toBe(2);
12+
expect(calculateMedian([1, 2, 3, 4, 5])).toBe(3);
13+
});
14+
15+
test("returns the average of middle values for even length array", () => {
16+
expect(calculateMedian([1, 2, 3, 4])).toBe(2.5);
17+
expect(calculateMedian([1, 2, 3, 4, 5, 6])).toBe(3.5);
18+
});
19+
20+
test("doesn't modify the input", () => {
21+
const list = [1, 2, 3];
22+
calculateMedian(list);
23+
24+
expect(list).toEqual([1, 2, 3]);
25+
});
26+
});

Sprint-1/implement/dedupe.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
function dedupe() {}

Sprint-1/implement/dedupe.test.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
const dedupe = require("./dedupe.js");
2+
/*
3+
Dedupe Array
4+
5+
📖 Dedupe means **deduplicate**
6+
7+
In this kata, you will need to deduplicate the elements of an array
8+
9+
E.g. dedupe(['a','a','a','b','b','c']) target output: ['a','b','c']
10+
E.g. dedupe([5, 1, 1, 2, 3, 2, 5, 8]) target output: [5, 1, 2, 3, 8]
11+
*/
12+
13+
// Acceptance Criteria:
14+
15+
// Given an empty array
16+
// When passed to the dedupe function
17+
// Then it should return an empty array
18+
test.todo("given an empty array, it returns an empty array");
19+
20+
// Given an array with no duplicates
21+
// When passed to the dedupe function
22+
// Then it should return a copy of the original array
23+
24+
// Given an array with strings or numbers
25+
// When passed to the dedupe function
26+
// Then it should remove the duplicate values
File renamed without changes.

Sprint-1/implement/max.test.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/* Find the maximum element of an array of numbers
2+
3+
In this kata, you will need to implement a function that sums the numerical elements of an array
4+
5+
E.g. max([30, 50, 10, 40]), target output: 50
6+
E.g. max(['hey', 10, 'hi', 60, 10]), target output: 60 (sum ignores any non-numerical elements)
7+
*/
8+
9+
// Given an empty array
10+
// When passed to the max function
11+
// Then it should return -Infinity
12+
test.todo("given an empty array, returns -Infinity");
13+
14+
// Given an array with one number
15+
// When passed to the max function
16+
// Then it should return that number
17+
18+
// Given an array with both positive and negative numbers
19+
// When passed to the max function
20+
// Then it should return the largest number overall
21+
22+
// Given an array with decimal numbers
23+
// When passed to the max function
24+
// Then it should return the largest decimal number
25+
26+
// Given an array with non-number values
27+
// When passed to the max function
28+
// Then it should return the max and ignore non-numeric values
File renamed without changes.

Sprint-1/implement/sum.test.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/* Sum the numbers in an array
2+
3+
In this kata, you will need to implement a function that sums the numerical elements of an array
4+
5+
E.g. sum([10, 20, 30]), target output: 60
6+
E.g. sum(['hey', 10, 'hi', 60, 10]), target output: 80 (ignore any non-numerical elements)
7+
*/
8+
9+
// Acceptance Criteria:
10+
11+
// Given an empty array
12+
// When passed to the sum function
13+
// Then it should return 0
14+
15+
// Given an array with just one number
16+
// When passed to the sum function
17+
// Then it should return that number
18+
19+
// Given an array containing negative numbers
20+
// When passed to the sum function
21+
// Then it should still return the correct total sum
22+
23+
// Given an array with decimal/float numbers
24+
// When passed to the sum function
25+
// Then it should return the correct total sum
26+
27+
// Given an array containing non-number values
28+
// When passed to the sum function
29+
// Then it should ignore the non-numerical values and return the sum of the numerical elements

Sprint-1/package.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "week-1",
3+
"version": "1.0.0",
4+
"description": "This README will guide you through the different sections for this week.",
5+
"main": "writers.js",
6+
"scripts": {
7+
"test": "jest"
8+
},
9+
"keywords": [],
10+
"author": "",
11+
"license": "ISC",
12+
"devDependencies": {
13+
"jest": "^29.7.0"
14+
}
15+
}

Sprint-1/readme.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# 🧭 Guide to Week 1 exercises
2+
3+
This README will guide you through the different sections for this week.
4+
5+
## Setup
6+
7+
Go to the **root of this repository**. Double check you're there with `pwd`. Also double check with `ls`.
8+
**If you're in the root you should be able to see the `week-1`, `week-2` and `week-3` directories**
9+
10+
Run the command `npm install` in the root of this repo.
11+
12+
To run tests in the `week-1` directory you can:
13+
14+
1. Change directory into `week-1`
15+
2. Run the tests using `npm test`
16+
17+
## Fix
18+
19+
In this section, you'll have a function and some tests. The function isn't working for all the tests - you'll need to:
20+
21+
- run the tests
22+
- interpret the test feedback
23+
- fix the tests
24+
25+
To run the tests for the `fix` directory you can `cd` into `week-1` and run `npm test -- fix`.
26+
27+
## 🔨 Implement
28+
29+
In this section, you will have a short set of requirements about a function. You will need to implement a function based off this set of requirements. Make sure you check your function works for a number of different inputs.
30+
31+
Here is a recommended order:
32+
33+
1. `max.test.js`
34+
2. `sum.test.js`
35+
3. `dedupe.test.js`
36+
37+
## 🧹 Refactor
38+
39+
In these problems, you'll be given an implementation and then asked to change it. Once you've updated the implementations you'll need to double check that they are still working!
40+
41+
Once you've completed all these tasks, raise a PR with your work so far. Don't wait to complete your coursework before completing the PR.
42+
43+
## Stretch 💪
44+
45+
Try the more challenging problem from Advent of Code!

0 commit comments

Comments
 (0)