Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 0987e46

Browse files
Sum of Differences
1 parent 9eefb98 commit 0987e46

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

‎16_Sum-of-Differences/index.js‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Sum of Differences
2+
// Write a function that takes a number array with two positive numbers and finds the sum of all the numbers between and including the smallest and largest values (the two original numbers in the array)
3+
4+
const sumOfDiff = numArr => {
5+
const [minNum, maxNum] = numArr.sort((num1, num2) => {
6+
return num1 - num2
7+
})
8+
let total = 0
9+
10+
for (let i = minNum; i <= maxNum; i++) {
11+
total += i
12+
}
13+
return total
14+
}
15+
16+
console.log(sumOfDiff([10, 5]))
17+
console.log(sumOfDiff([3, 7]))

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /