Reduce

modern reduce an array to total

by David McClelland

HTML

<div id="sandbox"></div>

CSS

.box {
  height: 40px;
  width: 40px;
  background-color: yellow;
  z-index: 1;
  margin: 10px;
}

#sandbox {
  background-color: black;
  width: 300px;
  height: 200px;
  display: flex;
}

JavaScript

const myArr = [2,3,4,5,6];

const getTotal = myArr.reduce( (num, total) => {
console.log(`num: ${num}, total: ${total}`);
	return num + total;
});

const doubleTotal = myArr.reduce((num, total) => {

   
console.log(getTotal);