Skip to content

Commit 3e887a6

Browse files
johnnyxbellegonSchiele
authored andcommitted
updated the 04_quicksort/javascript/01_loop_sum.js to a working soloution (egonSchiele#88)
1 parent 7dc9e95 commit 3e887a6

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed
Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
/**
22
* Sums values in array by loop "for"
33
* @param {Array} arr Array of numbers
4-
* @return {number} Sum of the numbers
4+
* @return {total} Sum of the numbers
55
*/
6-
function sumLoop( arr ) {
7-
var result = 0;
86

9-
for ( var i = 0; i < newArr.length; i++ ) {
10-
result += newArr[i];
7+
function sum(arr) {
8+
let total = 0;
9+
for (let i = 0; i < arr.length; i++) {
10+
total += arr[i];
1111
}
12-
13-
return result;
12+
return total;
1413
}
1514

16-
var arr = [1, 2, 3, 4];
17-
18-
console.log( sumLoop( arr ) ); // 10
15+
console.log(sum([1, 2, 3, 4])); // 10

0 commit comments

Comments
 (0)