Skip to content

Commit b8e32be

Browse files
authored
feat(curriculum): daily challenges 120-143 (freeCodeCamp#64173)
1 parent a6e5748 commit b8e32be

File tree

55 files changed

+4316
-3
lines changed

Some content is hidden

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

55 files changed

+4316
-3
lines changed

curriculum/challenges/english/blocks/daily-coding-challenges-javascript/69162d64f96574d9bb629efe.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Given a distance in miles as a number, return the equivalent distance in kilomet
1212
- The input will always be a non-negative number.
1313
- 1 mile equals 1.60934 kilometers.
1414
- Round the result to two decimal places.
15+
- Remove unnecessary trailing zeros from the rounded result.
1516

1617
# --hints--
1718

curriculum/challenges/english/blocks/daily-coding-challenges-javascript/69162d64f96574d9bb629f00.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ A valid ordered list item in Markdown must:
1818

1919
If the string doesn't have the exact format above, return `"Invalid format"`. Otherwise, wrap the list item text in `li` tags and return the string.
2020

21-
For example, given `"1. My item"`, return `"<li>My item</li>"`
21+
For example, given `"1. My item"`, return `"<li>My item</li>"`.
2222

2323
Note: The console may not display HTML tags in strings when logging messages. Check the browser console to see logs with tags included.
2424

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
---
2+
id: 691b559495c5cb5a37b9b480
3+
title: "Challenge 120: Pounds to Kilograms"
4+
challengeType: 28
5+
dashedName: challenge-120
6+
---
7+
8+
# --description--
9+
10+
Given a weight in pounds as a number, return the string `"(lbs) pounds equals (kgs) kilograms."`.
11+
12+
- Replace `"(lbs)"` with the input number.
13+
- Replace `"(kgs)"` with the input converted to kilograms, rounded to two decimals and always include two decimal places in the value.
14+
- 1 pound equals 0.453592 kilograms.
15+
- If the input is `1`, use `"pound"` instead of `"pounds"`.
16+
- If the converted value is `1`, use `"kilogram"` instead of `"kilograms"`.
17+
18+
# --hints--
19+
20+
`convertToKgs(1)` should return `"1 pound equals 0.45 kilograms."`.
21+
22+
```js
23+
assert.equal(convertToKgs(1), "1 pound equals 0.45 kilograms.");
24+
```
25+
26+
`convertToKgs(0)` should return `"0 pounds equals 0.00 kilograms."`.
27+
28+
```js
29+
assert.equal(convertToKgs(0), "0 pounds equals 0.00 kilograms.");
30+
```
31+
32+
`convertToKgs(100)` should return `"100 pounds equals 45.36 kilograms."`.
33+
34+
```js
35+
assert.equal(convertToKgs(100), "100 pounds equals 45.36 kilograms.");
36+
```
37+
38+
`convertToKgs(2.5)` should return `"2.5 pounds equals 1.13 kilograms."`.
39+
40+
```js
41+
assert.equal(convertToKgs(2.5), "2.5 pounds equals 1.13 kilograms.");
42+
```
43+
44+
`convertToKgs(2.20462)` should return `"2.20462 pounds equals 1.00 kilogram."`.
45+
46+
```js
47+
assert.equal(convertToKgs(2.20462), "2.20462 pounds equals 1.00 kilogram.");
48+
```
49+
50+
# --seed--
51+
52+
## --seed-contents--
53+
54+
```js
55+
function convertToKgs(lbs) {
56+
return lbs;
57+
}
58+
```
59+
60+
# --solutions--
61+
62+
```js
63+
function convertToKgs(lbs) {
64+
const KG_PER_POUND = 0.453592;
65+
const kgs = (lbs * KG_PER_POUND).toFixed(2);
66+
67+
const poundWord = lbs === 1 ? "pound" : "pounds";
68+
const kilogramWord = kgs === "1.00" ? "kilogram" : "kilograms";
69+
70+
return `${lbs} ${poundWord} equals ${kgs} ${kilogramWord}.`;
71+
}
72+
```
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
---
2+
id: 691b559495c5cb5a37b9b481
3+
title: "Challenge 121: Most Frequent"
4+
challengeType: 28
5+
dashedName: challenge-121
6+
---
7+
8+
# --description--
9+
10+
Given an array of elements, return the element that appears most frequently.
11+
12+
- There will always be a single most frequent element.
13+
14+
# --hints--
15+
16+
`mostFrequent(["a", "b", "a", "c"])` should return `"a"`.
17+
18+
```js
19+
assert.equal(mostFrequent(["a", "b", "a", "c"]), "a");
20+
```
21+
22+
`mostFrequent([2, 3, 5, 2, 6, 3, 2, 7, 2, 9])` should return `2`.
23+
24+
```js
25+
assert.equal(mostFrequent([2, 3, 5, 2, 6, 3, 2, 7, 2, 9]), 2);
26+
```
27+
28+
`mostFrequent([true, false, "false", "true", false])` should return `false`.
29+
30+
```js
31+
assert.isFalse(mostFrequent([true, false, "false", "true", false]));
32+
```
33+
34+
`mostFrequent([40, 20, 70, 30, 10, 40, 10, 50, 40, 60])` should return `40`.
35+
36+
```js
37+
assert.equal(mostFrequent([40, 20, 70, 30, 10, 40, 10, 50, 40, 60]), 40);
38+
```
39+
40+
# --seed--
41+
42+
## --seed-contents--
43+
44+
```js
45+
function mostFrequent(arr) {
46+
return arr;
47+
}
48+
```
49+
50+
# --solutions--
51+
52+
```js
53+
function mostFrequent(arr) {
54+
const freq = {};
55+
let maxCount = 0;
56+
let mostElem = null;
57+
58+
for (const el of arr) {
59+
freq[el] = (freq[el] || 0) + 1;
60+
if (freq[el] > maxCount) {
61+
maxCount = freq[el];
62+
mostElem = el;
63+
}
64+
}
65+
66+
return mostElem;
67+
}
68+
```
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
---
2+
id: 691b559495c5cb5a37b9b482
3+
title: "Challenge 122: Markdown Bold Parser"
4+
challengeType: 28
5+
dashedName: challenge-122
6+
---
7+
8+
# --description--
9+
10+
Given a string that may include some bold text in Markdown, return the equivalent HTML string.
11+
12+
- Bold text in Markdown is any text that starts and ends with two asterisks (`**`) or two underscores (`__`).
13+
- There cannot be any spaces between the text and the asterisks or underscores, but there can be
14+
spaces in the text itself.
15+
- Convert all bold occurrences to HTML `b` tags and return the string.
16+
17+
For example, given `"**This is bold**"`, return `"<b>This is bold</b>"`.
18+
19+
Note: The console may not display HTML tags in strings when logging messages. Check the browser console to see logs with tags included.
20+
21+
# --hints--
22+
23+
`parseBold("**This is bold**")` should return `"<b>This is bold</b>"`.
24+
25+
```js
26+
assert.equal(parseBold("**This is bold**"), "<b>This is bold</b>");
27+
```
28+
29+
`parseBold("__This is also bold__")` should return `"<b>This is also bold</b>"`.
30+
31+
```js
32+
assert.equal(parseBold("__This is also bold__"), "<b>This is also bold</b>");
33+
```
34+
35+
`parseBold("**This is not bold **")` should return `"**This is not bold **"`.
36+
37+
```js
38+
assert.equal(parseBold("**This is not bold **"), "**This is not bold **");
39+
```
40+
41+
`parseBold("__ This is also not bold__")` should return `"__ This is also not bold__"`.
42+
43+
```js
44+
assert.equal(parseBold("__ This is also not bold__"), "__ This is also not bold__");
45+
```
46+
47+
`parseBold("The **quick** brown fox __jumps__ over the **lazy** dog.")` should return `"The <b>quick</b> brown fox <b>jumps</b> over the <b>lazy</b> dog."`.
48+
49+
```js
50+
assert.equal(parseBold("The **quick** brown fox __jumps__ over the **lazy** dog."), "The <b>quick</b> brown fox <b>jumps</b> over the <b>lazy</b> dog.");
51+
```
52+
53+
# --seed--
54+
55+
## --seed-contents--
56+
57+
```js
58+
function parseBold(markdown) {
59+
return markdown;
60+
}
61+
```
62+
63+
# --solutions--
64+
65+
```js
66+
function parseBold(markdown) {
67+
markdown = markdown.replace(/\*\*(\S(?:.*?\S)?)\*\*/g, "<b>$1</b>");
68+
markdown = markdown.replace(/__(\S(?:.*?\S)?)__/g, "<b>$1</b>");
69+
70+
return markdown;
71+
}
72+
```
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
---
2+
id: 691b559495c5cb5a37b9b483
3+
title: "Challenge 123: Roman Numeral Builder"
4+
challengeType: 28
5+
dashedName: challenge-123
6+
---
7+
8+
# --description--
9+
10+
Given an integer, return its equivalent value in Roman numerals.
11+
12+
Roman numerals use these symbols:
13+
14+
| Symbol | Value |
15+
| ------ | ----- |
16+
| I | 1 |
17+
| V | 5 |
18+
| X | 10 |
19+
| L | 50 |
20+
| C | 100 |
21+
| D | 500 |
22+
| M | 1000 |
23+
24+
Roman numerals are written from largest to smallest, left to right using the following rules:
25+
26+
- Addition is used when a symbol is followed by one of equal or smaller value. For example, `18` is written as `XVIII` (10 + 5 + 1 + 1 + 1 = 18).
27+
- Subtraction is used when a smaller symbol appears before a larger one, to represent 4 or 9 in any place value. For example, 19 is written as `XIX` (10 + (10 - 1)).
28+
- No symbol may be repeated more than three times in a row. Subtraction is used when you would otherwise need to write a symbol more than three times in a row. So the largest number you can write is 3999.
29+
30+
Here's one more example: given `1464`, return `"MCDLXIV"` (1000 + (500 - 100) + 50 + 10 + (5 - 1)).
31+
32+
# --hints--
33+
34+
`toRoman(18)` should return `"XVIII"`.
35+
36+
```js
37+
assert.equal(toRoman(18), "XVIII");
38+
```
39+
40+
`toRoman(19)` should return `"XIX"`.
41+
42+
```js
43+
assert.equal(toRoman(19), "XIX");
44+
```
45+
46+
`toRoman(1464)` should return `"MCDLXIV"`.
47+
48+
```js
49+
assert.equal(toRoman(1464), "MCDLXIV");
50+
```
51+
52+
`toRoman(2025)` should return `"MMXXV"`.
53+
54+
```js
55+
assert.equal(toRoman(2025), "MMXXV");
56+
```
57+
58+
`toRoman(3999)` should return `"MMMCMXCIX"`.
59+
60+
```js
61+
assert.equal(toRoman(3999), "MMMCMXCIX");
62+
```
63+
64+
# --seed--
65+
66+
## --seed-contents--
67+
68+
```js
69+
function toRoman(num) {
70+
return num;
71+
}
72+
```
73+
74+
# --solutions--
75+
76+
```js
77+
function toRoman(num) {
78+
const symbols = [
79+
["M", 1000],
80+
["CM", 900],
81+
["D", 500],
82+
["CD", 400],
83+
["C", 100],
84+
["XC", 90],
85+
["L", 50],
86+
["XL", 40],
87+
["X", 10],
88+
["IX", 9],
89+
["V", 5],
90+
["IV", 4],
91+
["I", 1]
92+
];
93+
94+
let result = "";
95+
for (const [sym, val] of symbols) {
96+
while (num >= val) {
97+
result += sym;
98+
num -= val;
99+
}
100+
}
101+
return result;
102+
}
103+
```

0 commit comments

Comments
 (0)