Skip to content

Commit cb65db5

Browse files
moT01majestic-owl448Sembauke
authored
feat(curriculum): daily challenges 213-222 (freeCodeCamp#66191)
Co-authored-by: majestic-owl448 <26656284+majestic-owl448@users.noreply.github.com> Co-authored-by: Sem Bauke <sem@freecodecamp.org>
1 parent 4bbc74f commit cb65db5

25 files changed

Lines changed: 1984 additions & 3 deletions

curriculum/challenges/english/blocks/daily-coding-challenges-javascript/697a49e6ff50d756c9b69366.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ To determine the rating:
1313

1414
- Calculate the steepness of the hill by taking the drop divided by the distance.
1515
- Then, calculate the adjusted steepness based on the hill type:
16-
- `"Downhill"` multiply steepness by 1.2
16+
- `"Downhill"`: multiply steepness by 1.2
1717
- `"Slalom"`: multiply steepness by 0.9
1818
- `"Giant Slalom"`: multiply steepness by 1.0
1919

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
---
2+
id: 699c8e045ee7cb94ed2322d4
3+
title: "Challenge 213: Word Length Converter"
4+
challengeType: 28
5+
dashedName: challenge-213
6+
---
7+
8+
# --description--
9+
10+
Given a string of words, return a new string where each word is replaced by its length.
11+
12+
- Words in the given string will be separated by a single space
13+
- Keep the spaces in the returned string.
14+
15+
For example, given `"hello world"`, return `"5 5"`.
16+
17+
# --hints--
18+
19+
`convertWords("hello world")` should return `"5 5"`.
20+
21+
```js
22+
assert.equal(convertWords("hello world"), "5 5");
23+
```
24+
25+
`convertWords("Thanks and happy coding")` should return `"6 3 5 6"`.
26+
27+
```js
28+
assert.equal(convertWords("Thanks and happy coding"), "6 3 5 6");
29+
```
30+
31+
`convertWords("The quick brown fox jumps over the lazy dog")` should return `"3 5 5 3 5 4 3 4 3"`.
32+
33+
```js
34+
assert.equal(convertWords("The quick brown fox jumps over the lazy dog"), "3 5 5 3 5 4 3 4 3");
35+
```
36+
37+
`convertWords("Lorem ipsum dolor sit amet consectetur adipiscing elit donec ut ligula vehicula iaculis orci vel semper nisl")` should return `"5 5 5 3 4 11 10 4 5 2 6 8 7 4 3 6 4"`.
38+
39+
```js
40+
assert.equal(convertWords("Lorem ipsum dolor sit amet consectetur adipiscing elit donec ut ligula vehicula iaculis orci vel semper nisl"), "5 5 5 3 4 11 10 4 5 2 6 8 7 4 3 6 4");
41+
```
42+
43+
# --seed--
44+
45+
## --seed-contents--
46+
47+
```js
48+
function convertWords(str) {
49+
50+
return str;
51+
}
52+
```
53+
54+
# --solutions--
55+
56+
```js
57+
function convertWords(str) {
58+
return str
59+
.split(" ")
60+
.map(word => word.length)
61+
.join(" ");
62+
}
63+
```
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
---
2+
id: 699c8e045ee7cb94ed2322d5
3+
title: "Challenge 214: Domino Chain Validator"
4+
challengeType: 28
5+
dashedName: challenge-214
6+
---
7+
8+
# --description--
9+
10+
Given a 2D array representing a sequence of dominoes, determine whether it forms a valid chain.
11+
12+
- Each element in the array represents a domino and will be an array of two numbers from 1 to 6, (inclusive).
13+
- For the chain to be valid, the second number of each domino must match the first number of the next domino.
14+
- The first number of the first domino and the last number of the last domino don't need to match anything.
15+
16+
# --hints--
17+
18+
`isValidDominoChain([[1, 3], [3, 6], [6, 5]])` should return `true`.
19+
20+
```js
21+
assert.isTrue(isValidDominoChain([[1, 3], [3, 6], [6, 5]]));
22+
```
23+
24+
`isValidDominoChain([[6, 2], [3, 4], [4, 1]])` should return `false`.
25+
26+
```js
27+
assert.isFalse(isValidDominoChain([[6, 2], [3, 4], [4, 1]]));
28+
```
29+
30+
`isValidDominoChain([[2, 5], [5, 6], [5, 1]])` should return `false`.
31+
32+
```js
33+
assert.isFalse(isValidDominoChain([[2, 5], [5, 6], [5, 1]]));
34+
```
35+
36+
`isValidDominoChain([[4, 3], [3, 1], [1, 6], [6, 6], [6, 5], [5, 1], [1, 1], [1, 4], [4, 4], [4, 2]])` should return `true`.
37+
38+
```js
39+
assert.isTrue(isValidDominoChain([[4, 3], [3, 1], [1, 6], [6, 6], [6, 5], [5, 1], [1, 1], [1, 4], [4, 4], [4, 2]]));
40+
```
41+
42+
`isValidDominoChain([[2, 3], [3, 3], [3, 6], [6, 1], [1, 4], [3, 5], [5, 5], [5, 4], [4, 2], [2, 2]])` should return `false`.
43+
44+
```js
45+
assert.isFalse(isValidDominoChain([[2, 3], [3, 3], [3, 6], [6, 1], [1, 4], [3, 5], [5, 5], [5, 4], [4, 2], [2, 2]]));
46+
```
47+
48+
# --seed--
49+
50+
## --seed-contents--
51+
52+
```js
53+
function isValidDominoChain(dominoes) {
54+
55+
return dominoes;
56+
}
57+
```
58+
59+
# --solutions--
60+
61+
```js
62+
function isValidDominoChain(dominoes) {
63+
for (let i = 0; i < dominoes.length - 1; i++) {
64+
if (dominoes[i][1] !== dominoes[i+1][0]) return false
65+
}
66+
67+
return true;
68+
}
69+
```
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
---
2+
id: 699c8e045ee7cb94ed2322d6
3+
title: "Challenge 215: Parking Fee Calculator"
4+
challengeType: 28
5+
dashedName: challenge-215
6+
---
7+
8+
# --description--
9+
10+
Given two strings representing the time you parked your car and the time you picked it up, calculate the parking fee.
11+
12+
- The given strings will be in the format `"HH:MM"` using a 24-hour clock. So `"14:00"` is 2pm for example.
13+
- The first string will be the time you parked your car, and the second will be the time you picked it up.
14+
- If the pickup time is earlier than the entry time, it means the parking spanned past midnight into the next day.
15+
16+
Fee rules:
17+
18+
- Each hour parked costs $3.
19+
- Partial hours are rounded up to the next full hour.
20+
- If the parking spans overnight (past midnight), an additional $10 overnight fee is applied.
21+
- There is a minimum fee of $5 (only used if the total would be less than $5).
22+
23+
Return the total cost in the format `"$cost"`, `"$5"` for example.
24+
25+
# --hints--
26+
27+
`calculateParkingFee("09:00", "11:00")` should return `"$6"`.
28+
29+
```js
30+
assert.equal(calculateParkingFee("09:00", "11:00"), "$6");
31+
```
32+
33+
`calculateParkingFee("10:00", "10:30")` should return `"$5"`.
34+
35+
```js
36+
assert.equal(calculateParkingFee("10:00", "10:30"), "$5");
37+
```
38+
39+
`calculateParkingFee("08:10", "10:45")` should return `"$9"`.
40+
41+
```js
42+
assert.equal(calculateParkingFee("08:10", "10:45"), "$9");
43+
```
44+
45+
`calculateParkingFee("14:40", "23:10")` should return `"$27"`.
46+
47+
```js
48+
assert.equal(calculateParkingFee("14:40", "23:10"), "$27");
49+
```
50+
51+
`calculateParkingFee("18:15", "01:30")` should return `"$34"`.
52+
53+
```js
54+
assert.equal(calculateParkingFee("18:15", "01:30"), "$34");
55+
```
56+
57+
`calculateParkingFee("11:11", "11:10")` should return `"$82"`.
58+
59+
```js
60+
assert.equal(calculateParkingFee("11:11", "11:10"), "$82");
61+
```
62+
63+
# --seed--
64+
65+
## --seed-contents--
66+
67+
```js
68+
function calculateParkingFee(parkTime, pickupTime) {
69+
70+
return parkTime;
71+
}
72+
```
73+
74+
# --solutions--
75+
76+
```js
77+
function calculateParkingFee(parkTime, pickupTime) {
78+
function toMinutes(time) {
79+
const [hours, minutes] = time.split(":").map(Number);
80+
return hours * 60 + minutes;
81+
}
82+
83+
const entryMinutes = toMinutes(parkTime);
84+
const exitMinutes = toMinutes(pickupTime);
85+
86+
let totalMinutes;
87+
let overnight = false;
88+
89+
if (exitMinutes < entryMinutes) {
90+
overnight = true;
91+
totalMinutes = (24 * 60 - entryMinutes) + exitMinutes;
92+
} else {
93+
totalMinutes = exitMinutes - entryMinutes;
94+
}
95+
96+
const hours = Math.ceil(totalMinutes / 60);
97+
let cost = hours * 3;
98+
99+
if (overnight) {
100+
cost += 10;
101+
}
102+
103+
if (cost < 5) {
104+
cost = 5;
105+
}
106+
107+
return `$${cost}`;
108+
}
109+
```
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
---
2+
id: 699c8e045ee7cb94ed2322d7
3+
title: "Challenge 216: Pi Day"
4+
challengeType: 28
5+
dashedName: challenge-216
6+
---
7+
8+
# --description--
9+
10+
Happy pi (π) day!
11+
12+
Given an integer (`n`), where `n` is between 1 and 1000 (inclusive), return the `n`th decimal of π.
13+
14+
- Make sure to return a number not a string.
15+
16+
π with its first five decimals is 3.14159. So given `5` for example, return `9`, the fifth decimal.
17+
18+
You may have to find the first 1000 decimals of π somewhere.
19+
20+
# --hints--
21+
22+
`getPiDecimal(5)` should return `9`.
23+
24+
```js
25+
assert.strictEqual(getPiDecimal(5), 9);
26+
```
27+
28+
`getPiDecimal(10)` should return `5`.
29+
30+
```js
31+
assert.strictEqual(getPiDecimal(10), 5);
32+
```
33+
34+
`getPiDecimal(22)` should return `6`.
35+
36+
```js
37+
assert.strictEqual(getPiDecimal(22), 6);
38+
```
39+
40+
`getPiDecimal(39)` should return `7`.
41+
42+
```js
43+
assert.strictEqual(getPiDecimal(39), 7);
44+
```
45+
46+
`getPiDecimal(76)` should return `2`.
47+
48+
```js
49+
assert.strictEqual(getPiDecimal(76), 2);
50+
```
51+
52+
`getPiDecimal(384)` should return `4`.
53+
54+
```js
55+
assert.strictEqual(getPiDecimal(384), 4);
56+
```
57+
58+
`getPiDecimal(601)` should return `0`.
59+
60+
```js
61+
assert.strictEqual(getPiDecimal(601), 0);
62+
```
63+
64+
`getPiDecimal(1000)` should return `9`.
65+
66+
```js
67+
assert.strictEqual(getPiDecimal(1000), 9);
68+
```
69+
70+
# --seed--
71+
72+
## --seed-contents--
73+
74+
```js
75+
function getPiDecimal(n) {
76+
77+
return n;
78+
}
79+
```
80+
81+
# --solutions--
82+
83+
```js
84+
function getPiDecimal(n) {
85+
const pi = "31415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989"
86+
87+
return Number(pi[n]);
88+
}
89+
```

0 commit comments

Comments
 (0)