diff --git a/src/transformState.js b/src/transformState.js index a1eaa0640..c1bb13209 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) { + const { type } = action; + + switch (type) { + case 'addProperties': + Object.assign(state, action.extraData); + break; + + case 'removeProperties': + action.keysToRemove.forEach(key => { + delete state[key]; + }); + break; + + case 'clear': + Object.keys(state).forEach(key => delete state[key]); + break; + + default: + throw new Error(); + } + } + + return state; } module.exports = transformState;