Skip to content

Instantly share code, notes, and snippets.

@nkt
Last active October 15, 2015 15:06
Show Gist options
  • Save nkt/0551bbf3c7c262242048 to your computer and use it in GitHub Desktop.
Save nkt/0551bbf3c7c262242048 to your computer and use it in GitHub Desktop.
function todoReducer(state, action) {
switch (action.type) {
case 'ADD_TODO':
return [action.payload, ...state];
default:
return state;
}
}
const actions = [
{
type: 'ADD_TODO',
payload: 'Learn Redux'
},
{
type: 'ADD_TODO',
payload: 'Learn React'
}
];
const initialState = [];
const currentState = actions.reduce(todoReducer, initialState);
assert.equals([
'Learn Redux',
'Learn React'
], currentState);
const nums = [1, 2, 3];
const sum = nums.reduce((res, value) => {
return res + value;
}, 0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment