Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

javascript reducers

// function that takes in the current state, and an action to update it 
// you just pass whatever the action you want to perform on the current state
// and it will go ahead and update it 

const arr = [2, 10, 40];
const initValue = 0;

const sumWithInitValue = arr.reduce((prevValue, currentValue) => {
  		return prevValue + currentValue 
	}, initValue);


console.log(`sum is ${sumWithInitValue}`)	// > "sum is 52"
Source by jsbin.com #
 
PREVIOUS NEXT
Tagged: #javascript #reducers
ADD COMMENT
Topic
Name
3+8 =