Skip to content

Instantly share code, notes, and snippets.

@HeisenbergsCat
Last active August 12, 2017 20:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HeisenbergsCat/c012eed25c9c3bf0bb67705b232ea9c7 to your computer and use it in GitHub Desktop.
Save HeisenbergsCat/c012eed25c9c3bf0bb67705b232ea9c7 to your computer and use it in GitHub Desktop.
JS Bin// source https://jsbin.com/ruhoxom
<!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