diff --git a/src/transformState.js b/src/transformState.js index a1eaa0640..0fc7f2005 100644 --- a/src/transformState.js +++ b/src/transformState.js @@ -4,8 +4,30 @@ * @param {Object} state * @param {Object[]} actions */ + function transformState(state, actions) { // write code here + for (let i = 0; i < actions.length; i++) { + switch (actions[i].type) { + case 'addProperties': + Object.assign(state, { ...actions[i].extraData }); + break; + case 'removeProperties': + for (let j = 0; j < actions[i].keysToRemove.length; j++) { + delete state[actions[i].keysToRemove[j]]; + } + break; + case 'clear': + for (const key in state) { + delete state[key]; + } + break; + default: + continue; + } + } + + return state; } module.exports = transformState;