Last active
August 12, 2017 20:55
-
-
Save HeisenbergsCat/c012eed25c9c3bf0bb67705b232ea9c7 to your computer and use it in GitHub Desktop.
JS Bin// source https://jsbin.com/ruhoxom
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<script id="jsbin-javascript"> | |
function sumAll(arr) { | |
var arrayToSum = []; | |
var arr_max = Math.max.apply(null, arr); | |
var arr_min = Math.min.apply(null, arr); | |
var index = 0; | |
for(i = arr_min; i <= arr_max; i++) { | |
arrayToSum[index] = i; | |
index++; | |
} | |
var summedArray = arrayToSum.reduce( | |
function(accumulator, currentVal, currentIndex, array) { | |
return accumulator + currentVal; | |
}); | |
return summedArray; | |
} | |
var arr = [4, 1]; | |
var sum = sumAll(arr); | |
console.log(sum); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment