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