Skip to content

Commit e020939

Browse files
feat(curriculum): daily challenges 197-212 (freeCodeCamp#65864)
Co-authored-by: majestic-owl448 <26656284+majestic-owl448@users.noreply.github.com>
1 parent 941e965 commit e020939

37 files changed

Lines changed: 3137 additions & 3 deletions

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Given an array representing the weights of the athletes on a bobsled team and a
1212
- The length of the array determines the team size: 1, 2 or 4 person teams.
1313
- All given weight values are in kilograms (kg).
1414

15-
The bobsled (sled by iteself) must have a minimum weight of:
15+
The bobsled (sled by itself) must have a minimum weight of:
1616

1717
- 162 kg for a 1-person team
1818
- 170 kg for a 2-person team
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
---
2+
id: 698a1a73ade5ac0e19180fa0
3+
title: "Challenge 197: Blood Type Compatibility"
4+
challengeType: 28
5+
dashedName: challenge-197
6+
---
7+
8+
# --description--
9+
10+
Given a donor blood type and a recipient blood type, determine whether the donor can give blood to the recipient.
11+
12+
Each blood type consists of:
13+
14+
- A letter: `"A"`, `"B"`, `"AB"`, or `"O"`
15+
- And an Rh factor: `"+"` or `"-"`
16+
17+
Blood types will be one of the valid letters followed by an Rh factor. For example, `"AB+"` and `"O-"` are valid blood types.
18+
19+
Letter Rules:
20+
21+
- `"O"` can donate to other letter type.
22+
- `"A"` can donate to `"A"` and `"AB"`.
23+
- `"B"` can donate to `"B"` and `"AB"`.
24+
- `"AB"` can donate only to `"AB"`.
25+
26+
Rh Rules:
27+
28+
- Negative (`"-"`) can donate to both `"-"` and `"+"`.
29+
- Positive (`"+"`) can donate only to `"+"`.
30+
31+
Both letter and Rh rule must pass for a donor to be able to donate to the recipient.
32+
33+
# --hints--
34+
35+
`canDonate("B+", "B+")` should return `true`.
36+
37+
```js
38+
assert.isTrue(canDonate("B+", "B+"));
39+
```
40+
41+
`canDonate("O-", "AB-")` should return `true`.
42+
43+
```js
44+
assert.isTrue(canDonate("O-", "AB-"));
45+
```
46+
47+
`canDonate("O+", "A-")` should return `false`.
48+
49+
```js
50+
assert.isFalse(canDonate("O+", "A-"));
51+
```
52+
53+
`canDonate("A+", "AB+")` should return `true`.
54+
55+
```js
56+
assert.isTrue(canDonate("A+", "AB+"));
57+
```
58+
59+
`canDonate("A-", "B-")` should return `false`.
60+
61+
```js
62+
assert.isFalse(canDonate("A-", "B-"));
63+
```
64+
65+
`canDonate("B-", "AB+")` should return `true`.
66+
67+
```js
68+
assert.isTrue(canDonate("B-", "AB+"));
69+
```
70+
71+
`canDonate("B-", "A+")` should return `false`.
72+
73+
```js
74+
assert.isFalse(canDonate("B-", "A+"));
75+
```
76+
77+
`canDonate("O-", "O+")` should return `true`.
78+
79+
```js
80+
assert.isTrue(canDonate("O-", "O+"));
81+
```
82+
83+
`canDonate("O+", "O-")` should return `false`.
84+
85+
```js
86+
assert.isFalse(canDonate("O+", "O-"));
87+
```
88+
89+
`canDonate("AB+", "AB-")` should return `false`.
90+
91+
```js
92+
assert.isFalse(canDonate("AB+", "AB-"));
93+
```
94+
95+
# --seed--
96+
97+
## --seed-contents--
98+
99+
```js
100+
function canDonate(donor, recipient) {
101+
102+
return donor;
103+
}
104+
```
105+
106+
# --solutions--
107+
108+
```js
109+
function canDonate(donor, recipient) {
110+
const donorType = donor.slice(0, -1);
111+
const donorRh = donor.slice(-1);
112+
113+
const recipientType = recipient.slice(0, -1);
114+
const recipientRh = recipient.slice(-1);
115+
116+
const aboCompatibility = {
117+
"O": ["A", "B", "AB", "O"],
118+
"A": ["A", "AB"],
119+
"B": ["B", "AB"],
120+
"AB": ["AB"]
121+
};
122+
123+
const aboMatch = aboCompatibility[donorType].includes(recipientType);
124+
const rhMatch =
125+
donorRh === "-" || (donorRh === "+" && recipientRh === "+");
126+
127+
return aboMatch && rhMatch;
128+
}
129+
```
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
---
2+
id: 698a1a73ade5ac0e19180fa1
3+
title: "Challenge 198: Business Day Count"
4+
challengeType: 28
5+
dashedName: challenge-198
6+
---
7+
8+
# --description--
9+
10+
Given a start date and an end date, return the number of business days between the two.
11+
12+
- Given dates are in the format `"YYYY-MM-DD"`.
13+
- Weekdays are business days (Monday through Friday).
14+
- Weekends are not business days (Saturday and Sunday).
15+
- Include both the start and end dates when counting.
16+
17+
# --hints--
18+
19+
`countBusinessDays("2026-02-24", "2026-02-26")` should return `3`.
20+
21+
```js
22+
assert.equal(countBusinessDays("2026-02-24", "2026-02-26"), 3);
23+
```
24+
25+
`countBusinessDays("2026-02-24", "2026-02-28")` should return `4`.
26+
27+
```js
28+
assert.equal(countBusinessDays("2026-02-24", "2026-02-28"), 4);
29+
```
30+
31+
`countBusinessDays("2026-02-21", "2026-03-01")` should return `5`.
32+
33+
```js
34+
assert.equal(countBusinessDays("2026-02-21", "2026-03-01"), 5);
35+
```
36+
37+
`countBusinessDays("2026-03-08", "2026-03-17")` should return `7`.
38+
39+
```js
40+
assert.equal(countBusinessDays("2026-03-08", "2026-03-17"), 7);
41+
```
42+
43+
`countBusinessDays("2026-02-24", "2027-02-24")` should return `262`.
44+
45+
```js
46+
assert.equal(countBusinessDays("2026-02-24", "2027-02-24"), 262);
47+
```
48+
49+
# --seed--
50+
51+
## --seed-contents--
52+
53+
```js
54+
function countBusinessDays(start, end) {
55+
56+
return start;
57+
}
58+
```
59+
60+
# --solutions--
61+
62+
```js
63+
function countBusinessDays(start, end) {
64+
const startDate = new Date(start + "T00:00:00Z");
65+
const endDate = new Date(end + "T00:00:00Z");
66+
67+
let count = 0;
68+
let current = new Date(startDate);
69+
70+
while (current <= endDate) {
71+
const day = current.getUTCDay();
72+
if (day !== 0 && day !== 6) count++;
73+
current.setUTCDate(current.getUTCDate() + 1);
74+
}
75+
76+
return count;
77+
}
78+
```
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
---
2+
id: 698a1a73ade5ac0e19180fa2
3+
title: "Challenge 199: Sequential Difference"
4+
challengeType: 28
5+
dashedName: challenge-199
6+
---
7+
8+
# --description--
9+
10+
Given an array of numbers, return a new array containing the value needed to get from each number to the next number.
11+
12+
- For the last number, use `0` since there is no next number.
13+
14+
For example, given `[1, 2, 4, 7]`, return `[1, 2, 3, 0]`.
15+
16+
# --hints--
17+
18+
`findDifferences([1, 2, 4, 7])` should return `[1, 2, 3, 0]`.
19+
20+
```js
21+
assert.deepEqual(findDifferences([1, 2, 4, 7]), [1, 2, 3, 0]);
22+
```
23+
24+
`findDifferences([10, 15, 19, 22, 24, 25])` should return `[5, 4, 3, 2, 1, 0]`.
25+
26+
```js
27+
assert.deepEqual(findDifferences([10, 15, 19, 22, 24, 25]), [5, 4, 3, 2, 1, 0]);
28+
```
29+
30+
`findDifferences([25, 20, 16, 13, 11, 10])` should return `[-5, -4, -3, -2, -1, 0]`.
31+
32+
```js
33+
assert.deepEqual(findDifferences([25, 20, 16, 13, 11, 10]), [-5, -4, -3, -2, -1, 0]);
34+
```
35+
36+
`findDifferences([0, 1, 2, 2, 3, 3, 4, 5])` should return `[ 1, 1, 0, 1, 0, 1, 1, 0 ]`.
37+
38+
```js
39+
assert.deepEqual(findDifferences([0, 1, 2, 2, 3, 3, 4, 5]), [ 1, 1, 0, 1, 0, 1, 1, 0 ]);
40+
```
41+
42+
`findDifferences([1, 2, 5, 12, 34, -15, -1, 41, 113, -222, -99, -40, 10, -18, -6, -2, -1])` should return `[1, 3, 7, 22, -49, 14, 42, 72, -335, 123, 59, 50, -28, 12, 4, 1, 0]`.
43+
44+
```js
45+
assert.deepEqual(findDifferences([1, 2, 5, 12, 34, -15, -1, 41, 113, -222, -99, -40, 10, -18, -6, -2, -1]), [1, 3, 7, 22, -49, 14, 42, 72, -335, 123, 59, 50, -28, 12, 4, 1, 0]);
46+
```
47+
48+
# --seed--
49+
50+
## --seed-contents--
51+
52+
```js
53+
function findDifferences(arr) {
54+
55+
return arr;
56+
}
57+
```
58+
59+
# --solutions--
60+
61+
```js
62+
function findDifferences(arr) {
63+
const result = [];
64+
65+
for (let i = 0; i < arr.length; i++) {
66+
result.push(arr[i + 1] - arr[i] || 0);
67+
}
68+
69+
return result;
70+
}
71+
```
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
---
2+
id: 698a1a73ade5ac0e19180fa3
3+
title: "Challenge 200: Letter and Number Count"
4+
challengeType: 28
5+
dashedName: challenge-200
6+
---
7+
8+
# --description--
9+
10+
Given a string, return a message with the count of how many letters and numbers it contains.
11+
12+
- Letters are `A-Z` and `a-z`.
13+
- Numbers are `0-9`.
14+
- Ignore all other characters.
15+
16+
Return `"The string has X letters and Y numbers."`, where `"X"` is the count of letters and `"Y"` is the count of numbers. If either count is 1, use the singular form for that item. E.g: `"1 letter"` instead of `"1 letters"` and `"1 number"` instead of `"1 numbers"`.
17+
18+
# --hints--
19+
20+
`countLettersAndNumbers("helloworld123")` should return `"The string has 10 letters and 3 numbers."`.
21+
22+
```js
23+
assert.equal(countLettersAndNumbers("helloworld123"), "The string has 10 letters and 3 numbers.");
24+
```
25+
26+
`countLettersAndNumbers("Catch 22")` should return `"The string has 5 letters and 2 numbers."`.
27+
28+
```js
29+
assert.equal(countLettersAndNumbers("Catch 22"), "The string has 5 letters and 2 numbers.");
30+
```
31+
32+
`countLettersAndNumbers("A1!")` should return `"The string has 1 letter and 1 number."`.
33+
34+
```js
35+
assert.equal(countLettersAndNumbers("A1!"), "The string has 1 letter and 1 number.");
36+
```
37+
38+
`countLettersAndNumbers("12345")` should return `"The string has 0 letters and 5 numbers."`.
39+
40+
```js
41+
assert.equal(countLettersAndNumbers("12345"), "The string has 0 letters and 5 numbers.");
42+
```
43+
44+
`countLettersAndNumbers("password")` should return `"The string has 8 letters and 0 numbers."`.
45+
46+
```js
47+
assert.equal(countLettersAndNumbers("password"), "The string has 8 letters and 0 numbers.");
48+
```
49+
50+
# --seed--
51+
52+
## --seed-contents--
53+
54+
```js
55+
function countLettersAndNumbers(str) {
56+
57+
return str;
58+
}
59+
```
60+
61+
# --solutions--
62+
63+
```js
64+
function countLettersAndNumbers(str) {
65+
let letterCount = 0;
66+
let numberCount = 0;
67+
68+
for (let char of str) {
69+
if ((char >= 'A' && char <= 'Z') || (char >= 'a' && char <= 'z')) {
70+
letterCount++;
71+
} else if (char >= '0' && char <= '9') {
72+
numberCount++;
73+
}
74+
}
75+
76+
const letterWord = letterCount === 1 ? "letter" : "letters";
77+
const numberWord = numberCount === 1 ? "number" : "numbers";
78+
79+
return `The string has ${letterCount} ${letterWord} and ${numberCount} ${numberWord}.`;
80+
}
81+
```

0 commit comments

Comments
 (0)