Skip to content

Commit c71e838

Browse files
authored
feat(curriculum): daily challenges 144-160 (freeCodeCamp#64530)
1 parent de75200 commit c71e838

37 files changed

+3062
-1
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
---
2+
id: 69306364df283fcaff2e1ad5
3+
title: "Challenge 144: Resolution Streak"
4+
challengeType: 28
5+
dashedName: challenge-144
6+
---
7+
8+
# --description--
9+
10+
Given an array of arrays, where each sub-array represents a day of your resolution activities and contains three integers: the number of steps walked that day, the minutes of screen time that day, and the number of pages read that day; determine if you are keeping your resolutions.
11+
12+
- The first sub-array is day 1, and second day 2, and so on.
13+
14+
A day is considered successful if all three of the following goals are met:
15+
16+
- You walked at least 10,000 steps.
17+
- You had no more than 120 minutes of screen time.
18+
- You read at least five pages.
19+
20+
If all of the given days are successful, return `"Resolution on track: N day streak."` Where `N` is the number of successful days.
21+
22+
If one or more days is not a success, return `"Resolution failed on day X: N day streak."`. Where `X` is the day number of the first unsuccessful day, and `N` is the number of successful days before the first unsuccessful day.
23+
24+
# --hints--
25+
26+
`resolutionStreak([[10500, 75, 15], [11000, 90, 10], [10650, 100, 9]])` should return `"Resolution on track: 3 day streak."`
27+
28+
```js
29+
assert.equal(resolutionStreak([[10500, 75, 15], [11000, 90, 10], [10650, 100, 9]]), "Resolution on track: 3 day streak.");
30+
```
31+
32+
`resolutionStreak([[10000, 120, 5], [10950, 121, 11]])` should return `"Resolution failed on day 2: 1 day streak."`
33+
34+
```js
35+
assert.equal(resolutionStreak([[10000, 120, 5], [10950, 121, 11]]), "Resolution failed on day 2: 1 day streak.");
36+
```
37+
38+
`resolutionStreak([[15000, 110, 8], [12300, 60, 13], [10100, 120, 4], [9000, 125, 4]])` should return `"Resolution failed on day 3: 2 day streak."`
39+
40+
```js
41+
assert.equal(resolutionStreak([[15000, 110, 8], [12300, 60, 13], [10100, 120, 4], [9000, 125, 4]]), "Resolution failed on day 3: 2 day streak.");
42+
```
43+
44+
`resolutionStreak([[11600, 76, 13], [12556, 64, 26], [10404, 32, 59], [9999, 44, 124], [7508, 23, 167], [10900, 80, 0]])` should return `"Resolution failed on day 4: 3 day streak."`
45+
46+
```js
47+
assert.equal(resolutionStreak([[11600, 76, 13], [12556, 64, 26], [10404, 32, 59], [9999, 44, 124], [7508, 23, 167], [10900, 80, 0]]), "Resolution failed on day 4: 3 day streak.");
48+
```
49+
50+
`resolutionStreak([[10500, 75, 15], [11000, 90, 10], [10650, 100, 9], [10200, 60, 10], [10678, 87, 9], [12431, 67, 13], [10444, 107, 19], [10111, 95, 5], [10000, 120, 7], [11980, 101, 8]])` should return `"Resolution on track: 10 day streak."`
51+
52+
```js
53+
assert.equal(resolutionStreak([[10500, 75, 15], [11000, 90, 10], [10650, 100, 9], [10200, 60, 10], [10678, 87, 9], [12431, 67, 13], [10444, 107, 19], [10111, 95, 5], [10000, 120, 7], [11980, 101, 8]]), "Resolution on track: 10 day streak.");
54+
```
55+
56+
# --seed--
57+
58+
## --seed-contents--
59+
60+
```js
61+
function resolutionStreak(days) {
62+
63+
return days;
64+
}
65+
```
66+
67+
# --solutions--
68+
69+
```js
70+
function resolutionStreak(days) {
71+
let streak = 0;
72+
73+
for (let i = 0; i < days.length; i++) {
74+
const [steps, screen, pages] = days[i];
75+
if (steps >= 10000 && screen <= 120 && pages >= 5) {
76+
streak++;
77+
} else {
78+
return `Resolution failed on day ${i + 1}: ${streak} day streak.`;
79+
}
80+
}
81+
82+
return `Resolution on track: ${streak} day streak.`;
83+
}
84+
```
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
---
2+
id: 69306364df283fcaff2e1ad6
3+
title: "Challenge 145: Nth Fibonacci Number"
4+
challengeType: 28
5+
dashedName: challenge-145
6+
---
7+
8+
# --description--
9+
10+
Given an integer `n`, return the `n`th number in the fibonacci sequence.
11+
12+
The Fibonacci sequence is a series of numbers where each number is the sum of the two preceding ones. The first 10 numbers in the sequence are `0`, `1`, `1`, `2`, `3`, `5`, `8`, `13`, `21`, `34`.
13+
14+
# --hints--
15+
16+
`nthFibonacci(4)` should return `2`.
17+
18+
```js
19+
assert.equal(nthFibonacci(4), 2);
20+
```
21+
22+
`nthFibonacci(10)` should return `34`.
23+
24+
```js
25+
assert.equal(nthFibonacci(10), 34);
26+
```
27+
28+
`nthFibonacci(15)` should return `377`.
29+
30+
```js
31+
assert.equal(nthFibonacci(15), 377);
32+
```
33+
34+
`nthFibonacci(40)` should return `63245986`.
35+
36+
```js
37+
assert.equal(nthFibonacci(40), 63245986);
38+
```
39+
40+
`nthFibonacci(75)` should return `1304969544928657`.
41+
42+
```js
43+
assert.equal(nthFibonacci(75), 1304969544928657);
44+
```
45+
46+
# --seed--
47+
48+
## --seed-contents--
49+
50+
```js
51+
function nthFibonacci(n) {
52+
53+
return n;
54+
}
55+
```
56+
57+
# --solutions--
58+
59+
```js
60+
function nthFibonacci(n) {
61+
if (n === 1) return 0;
62+
if (n === 2) return 1;
63+
64+
let a = 0;
65+
let b = 1;
66+
67+
for (let i = 3; i <= n; i++) {
68+
const next = a + b;
69+
a = b;
70+
b = next;
71+
}
72+
73+
return b;
74+
}
75+
```
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
---
2+
id: 69306364df283fcaff2e1ad7
3+
title: "Challenge 146: Left-Handed Seat at the Table"
4+
challengeType: 28
5+
dashedName: challenge-146
6+
---
7+
8+
# --description--
9+
10+
Given a 4x2 matrix (array of arrays) representing the seating arrangement for a meal, determine how many seats a left-handed person can sit at.
11+
12+
- A left-handed person cannot sit where a right-handed person would be in the seat to the immediate left of them.
13+
14+
In the given matrix:
15+
16+
- An `"R"` is a seat occupied by a right-handed person.
17+
- An `"L"` is a seat occupied by a left-handed person.
18+
- An `"U"` is an unoccupied seat.
19+
- Only unoccupied seats are available to sit at.
20+
- The seats in the top row are facing "down", and the seats in the bottom row are facing "up" (like a table), so left and right are relative to the seat's orientation.
21+
- Corner seats only have one seat next to them.
22+
23+
For example, in the given matrix:
24+
25+
```json
26+
[
27+
["U", "R", "U", "L"],
28+
["U", "R", "R", "R"]
29+
]
30+
```
31+
32+
The top-left seat is cannot be sat in because there's a right-handed person to the left. The other two open seats can be sat in because there isn't a right-handed person to the left.
33+
34+
# --hints--
35+
36+
`findLeftHandedSeats([["U", "R", "U", "L"], ["U", "R", "R", "R"]])` should return `2`.
37+
38+
```js
39+
assert.equal(findLeftHandedSeats([["U", "R", "U", "L"], ["U", "R", "R", "R"]]), 2);
40+
```
41+
42+
`findLeftHandedSeats([["U", "U", "U", "U"], ["U", "U", "U", "U"]])` should return `8`.
43+
44+
```js
45+
assert.equal(findLeftHandedSeats([["U", "U", "U", "U"], ["U", "U", "U", "U"]]), 8);
46+
```
47+
48+
`findLeftHandedSeats([["U", "R", "U", "R"], ["L", "R", "R", "U"]])` should return `0`.
49+
50+
```js
51+
assert.equal(findLeftHandedSeats([["U", "R", "U", "R"], ["L", "R", "R", "U"]]), 0);
52+
```
53+
54+
`findLeftHandedSeats([["L", "U", "R", "R"], ["L", "U", "R", "R"]])` should return `1`.
55+
56+
```js
57+
assert.equal(findLeftHandedSeats([["L", "U", "R", "R"], ["L", "U", "R", "R"]]), 1);
58+
```
59+
60+
`findLeftHandedSeats([["U", "R", "U", "U"], ["U", "U", "L", "U"]])` should return `5`.
61+
62+
```js
63+
assert.equal(findLeftHandedSeats([["U", "R", "U", "U"], ["U", "U", "L", "U"]]), 5);
64+
```
65+
66+
# --seed--
67+
68+
## --seed-contents--
69+
70+
```js
71+
function findLeftHandedSeats(table) {
72+
73+
return table;
74+
}
75+
```
76+
77+
# --solutions--
78+
79+
```js
80+
function findLeftHandedSeats(table) {
81+
let availableSeats = 0;
82+
83+
const [topRow, bottomRow] = table;
84+
85+
for (let i=0; i<topRow.length; i++) {
86+
if (topRow[i] === 'U') {
87+
if (i === 3) {
88+
availableSeats++;
89+
} else if (topRow[i+1] !== 'R') {
90+
availableSeats++;
91+
}
92+
}
93+
}
94+
95+
for (let i=0; i<bottomRow.length; i++) {
96+
if (bottomRow[i] === 'U') {
97+
if (i === 0) {
98+
availableSeats++;
99+
} else if (bottomRow[i-1] !== 'R') {
100+
availableSeats++;
101+
}
102+
}
103+
}
104+
105+
return availableSeats;
106+
}
107+
```
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
---
2+
id: 69306364df283fcaff2e1ad8
3+
title: "Challenge 147: Leap Year Calculator"
4+
challengeType: 28
5+
dashedName: challenge-147
6+
---
7+
8+
# --description--
9+
10+
Given an integer year, determine whether it is a leap year.
11+
12+
A year is a leap year if it satisfies the following rules:
13+
14+
- The year is evenly divisible by 4, and
15+
- The year is not evenly divisible by 100, unless
16+
- The year is evenly divisible by 400.
17+
18+
# --hints--
19+
20+
`isLeapYear(2024)` should return `true`.
21+
22+
```js
23+
assert.isTrue(isLeapYear(2024));
24+
```
25+
26+
`isLeapYear(2023)` should return `false`.
27+
28+
```js
29+
assert.isFalse(isLeapYear(2023));
30+
```
31+
32+
`isLeapYear(2100)` should return `false`.
33+
34+
```js
35+
assert.isFalse(isLeapYear(2100));
36+
```
37+
38+
`isLeapYear(2000)` should return `true`.
39+
40+
```js
41+
assert.isTrue(isLeapYear(2000));
42+
```
43+
44+
`isLeapYear(1999)` should return `false`.
45+
46+
```js
47+
assert.isFalse(isLeapYear(1999));
48+
```
49+
50+
`isLeapYear(2040)` should return `true`.
51+
52+
```js
53+
assert.isTrue(isLeapYear(2040));
54+
```
55+
56+
`isLeapYear(2026)` should return `false`.
57+
58+
```js
59+
assert.isFalse(isLeapYear(2026));
60+
```
61+
62+
# --seed--
63+
64+
## --seed-contents--
65+
66+
```js
67+
function isLeapYear(year) {
68+
69+
return year;
70+
}
71+
```
72+
73+
# --solutions--
74+
75+
```js
76+
function isLeapYear(year) {
77+
return ((year % 4 === 0 && year % 100 !== 0) || (year % 400 === 0))
78+
}
79+
```

0 commit comments

Comments
 (0)