diff --git a/src/transformState.js b/src/transformState.js index a1eaa064..fbdba165 100644 --- a/src/transformState.js +++ b/src/transformState.js @@ -5,7 +5,35 @@ * @param {Object[]} actions */ function transformState(state, actions) { - // write code here + for (const action of actions) { + const { type, extraData, keysToRemove } = action; + + switch (type) { + case 'clear': { + for (const s in state) { + delete state[s]; + } + break; + } + + case 'addProperties': { + Object.assign(state, extraData); + break; + } + + case 'removeProperties': { + for (const key of keysToRemove) { + delete state[key]; + } + break; + } + + default: + return 'Unexpected action'; + }; + }; + + return state; } module.exports = transformState;