Skip to content

Commit 6c38557

Browse files
jdwilkin4Dario-DCmoT01
authored
feat(curriculum): add sum all numbers algorithm (freeCodeCamp#60409)
Co-authored-by: Dario-DC <105294544+Dario-DC@users.noreply.github.com> Co-authored-by: moT01 <20648924+moT01@users.noreply.github.com>
1 parent f6c715f commit 6c38557

6 files changed

Lines changed: 111 additions & 0 deletions

File tree

client/i18n/locales/english/intro.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2973,6 +2973,12 @@
29732973
"In this lab, you'll build a password generator app based on the user's input."
29742974
]
29752975
},
2976+
"lab-sum-all-numbers-algorithm": {
2977+
"title": "Design a Sum All Numbers Algorithm",
2978+
"intro": [
2979+
"In this lab, you will design a sum all numbers algorithm. This algorithm takes an array of two numbers and returns the sum of those two numbers plus the sum of all the numbers between them."
2980+
]
2981+
},
29762982
"review-javascript-fundamentals": {
29772983
"title": "JavaScript Fundamentals Review",
29782984
"intro": [
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
title: Introduction to the Design a Sum All Numbers Algorithm
3+
block: lab-sum-all-numbers-algorithm
4+
superBlock: full-stack-developer
5+
---
6+
7+
## Introduction to the Design a Sum All Numbers Algorithm
8+
9+
In this lab, you will design a sum all numbers algorithm. This algorithm takes an array of two numbers and returns the sum of those two numbers plus the sum of all the numbers between them.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "Design a Sum All Numbers Algorithm",
3+
"isUpcomingChange": false,
4+
"usesMultifileEditor": true,
5+
"blockType": "lab",
6+
"blockLayout": "link",
7+
"dashedName": "lab-sum-all-numbers-algorithm",
8+
"superBlock": "full-stack-developer",
9+
"challengeOrder": [{ "id": "a3566b1109230028080c9345", "title": "Design a Sum All Numbers Algorithm" }],
10+
"helpCategory": "JavaScript"
11+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
---
2+
id: a3566b1109230028080c9345
3+
title: Design a Sum All Numbers Algorithm
4+
challengeType: 26
5+
dashedName: lab-sum-all-numbers-algorithm
6+
---
7+
8+
# --description--
9+
10+
In this lab, you will need to design a sum all numbers algorithm.
11+
12+
Fulfill the user stories below and get all the tests to pass to complete the lab.
13+
14+
**User Stories:**
15+
16+
1. You should have a function named `sumAll` that accepts an array of two numbers.
17+
1. `sumAll([n, m])` should return the sum of `n` and `m` plus the sum of all the numbers between them. The lowest number will not always come first. For example, `sumAll([4,1])` should return `10` because sum of all the numbers between `1` and `4` (both inclusive) is `10`.
18+
19+
# --hints--
20+
21+
You should have a function named `sumAll`.
22+
23+
```js
24+
assert.isFunction(sumAll);
25+
```
26+
27+
`sumAll([1, 4])` should return a number.
28+
29+
```js
30+
assert.isNumber(sumAll([1, 4]));
31+
```
32+
33+
`sumAll([1, 4])` should return `10`.
34+
35+
```js
36+
assert.equal(sumAll([1, 4]), 10);
37+
```
38+
39+
`sumAll([4, 1])` should return `10`.
40+
41+
```js
42+
assert.equal(sumAll([4, 1]), 10);
43+
```
44+
45+
`sumAll([5, 10])` should return `45`.
46+
47+
```js
48+
assert.equal(sumAll([5, 10]), 45);
49+
```
50+
51+
`sumAll([10, 5])` should return `45`.
52+
53+
```js
54+
assert.equal(sumAll([10, 5]), 45);
55+
```
56+
57+
# --seed--
58+
59+
## --seed-contents--
60+
61+
```js
62+
```
63+
64+
# --solutions--
65+
66+
```js
67+
function sumAll(arr) {
68+
let sum = 0;
69+
70+
arr.sort((a, b) => a - b);
71+
72+
for (var i = arr[0]; i <= arr[1]; i++) {
73+
sum += i;
74+
}
75+
76+
return sum;
77+
}
78+
```

curriculum/superblock-structure/full-stack.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,9 @@
716716
{
717717
"dashedName": "lab-password-generator"
718718
},
719+
{
720+
"dashedName": "lab-sum-all-numbers-algorithm"
721+
},
719722
{
720723
"dashedName": "review-javascript-fundamentals"
721724
},

curriculum/test/utils/mongo-ids.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,6 +1042,10 @@ const duplicatedProjectIds = [
10421042

10431043
/*** JavaScript ***/
10441044

1045+
// Sum all numbers in range challenge (used in JS fundamentals review module)
1046+
1047+
'a3566b1109230028080c9345',
1048+
10451049
// Local Storage ToDo App
10461050

10471051
'64e4e4c4ec263b62ae7bf54d',

0 commit comments

Comments
 (0)