feat(curriculum): add sum all numbers algorithm (#60409)

Co-authored-by: Dario-DC <105294544+Dario-DC@users.noreply.github.com>
Co-authored-by: moT01 <20648924+moT01@users.noreply.github.com>
This commit is contained in:
Jessica Wilkins
2025-05-21 11:40:23 -07:00
committed by GitHub
parent f6c715f1b6
commit 6c38557ed9
6 changed files with 111 additions and 0 deletions
+6
View File
@@ -2973,6 +2973,12 @@
"In this lab, you'll build a password generator app based on the user's input."
]
},
"lab-sum-all-numbers-algorithm": {
"title": "Design a Sum All Numbers Algorithm",
"intro": [
"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."
]
},
"review-javascript-fundamentals": {
"title": "JavaScript Fundamentals Review",
"intro": [
@@ -0,0 +1,9 @@
---
title: Introduction to the Design a Sum All Numbers Algorithm
block: lab-sum-all-numbers-algorithm
superBlock: full-stack-developer
---
## Introduction to the Design a Sum All Numbers Algorithm
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.
@@ -0,0 +1,11 @@
{
"name": "Design a Sum All Numbers Algorithm",
"isUpcomingChange": false,
"usesMultifileEditor": true,
"blockType": "lab",
"blockLayout": "link",
"dashedName": "lab-sum-all-numbers-algorithm",
"superBlock": "full-stack-developer",
"challengeOrder": [{ "id": "a3566b1109230028080c9345", "title": "Design a Sum All Numbers Algorithm" }],
"helpCategory": "JavaScript"
}
@@ -0,0 +1,78 @@
---
id: a3566b1109230028080c9345
title: Design a Sum All Numbers Algorithm
challengeType: 26
dashedName: lab-sum-all-numbers-algorithm
---
# --description--
In this lab, you will need to design a sum all numbers algorithm.
Fulfill the user stories below and get all the tests to pass to complete the lab.
**User Stories:**
1. You should have a function named `sumAll` that accepts an array of two numbers.
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`.
# --hints--
You should have a function named `sumAll`.
```js
assert.isFunction(sumAll);
```
`sumAll([1, 4])` should return a number.
```js
assert.isNumber(sumAll([1, 4]));
```
`sumAll([1, 4])` should return `10`.
```js
assert.equal(sumAll([1, 4]), 10);
```
`sumAll([4, 1])` should return `10`.
```js
assert.equal(sumAll([4, 1]), 10);
```
`sumAll([5, 10])` should return `45`.
```js
assert.equal(sumAll([5, 10]), 45);
```
`sumAll([10, 5])` should return `45`.
```js
assert.equal(sumAll([10, 5]), 45);
```
# --seed--
## --seed-contents--
```js
```
# --solutions--
```js
function sumAll(arr) {
let sum = 0;
arr.sort((a, b) => a - b);
for (var i = arr[0]; i <= arr[1]; i++) {
sum += i;
}
return sum;
}
```
@@ -716,6 +716,9 @@
{
"dashedName": "lab-password-generator"
},
{
"dashedName": "lab-sum-all-numbers-algorithm"
},
{
"dashedName": "review-javascript-fundamentals"
},
+4
View File
@@ -1042,6 +1042,10 @@ const duplicatedProjectIds = [
/*** JavaScript ***/
// Sum all numbers in range challenge (used in JS fundamentals review module)
'a3566b1109230028080c9345',
// Local Storage ToDo App
'64e4e4c4ec263b62ae7bf54d',