<div id="before"></div>
<div id="after"></div>
body {
font-family: monospace;
margin: 20px;
font-size: 20px;
}
View Compiled
var arr = [1, 2, 3, 4, 5];
// reduce to a single value by summing them
var result = arr.reduce(function (accumulator, currentValue) {
return accumulator + currentValue;
}, 0);
// join the arrays with commas and print to page
print("before", "before: " + arr.join(', '));
print("after", "after: " + result);
function print(id, html) {
document.getElementById(id).innerHTML = html;
}
View Compiled
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.