updated the 04_quicksort/javascript/01_loop_sum.js to a working soloution (#88)

This commit is contained in:
Johnny Bell
2018-10-18 08:26:17 -07:00
committed by Aditya Bhargava
parent 7dc9e95d2a
commit 3e887a6d3c

View File

@@ -1,18 +1,15 @@
/**
* Sums values in array by loop "for"
* @param {Array} arr Array of numbers
* @return {number} Sum of the numbers
* @return {total} Sum of the numbers
*/
function sumLoop( arr ) {
var result = 0;
for ( var i = 0; i < newArr.length; i++ ) {
result += newArr[i];
function sum(arr) {
let total = 0;
for (let i = 0; i < arr.length; i++) {
total += arr[i];
}
return result;
return total;
}
var arr = [1, 2, 3, 4];
console.log( sumLoop( arr ) ); // 10
console.log(sum([1, 2, 3, 4])); // 10