diff --git a/src/transformState.js b/src/transformState.js index a1eaa0640..b03718699 100644 --- a/src/transformState.js +++ b/src/transformState.js @@ -5,7 +5,30 @@ * @param {Object[]} actions */ function transformState(state, actions) { - // write code here + for (const action of actions) { + switch (action.type) { + case 'addProperties': + Object.assign(state, action.extraData); + + break; + + case 'removeProperties': + action.keysToRemove.forEach(removeKey => { + delete state[removeKey]; + }); + + break; + + case 'clear': + Object.keys(state).forEach(key => { + delete state[key]; + }); + + break; + + default : return Error('something went wrong'); + } + } } module.exports = transformState;