diff --git a/src/transformState.js b/src/transformState.js index a1eaa064..d6bbd808 100644 --- a/src/transformState.js +++ b/src/transformState.js @@ -5,7 +5,25 @@ * @param {Object[]} actions */ function transformState(state, actions) { - // write code here + for (const action of actions) { + if (action.hasOwnProperty('type') && action.type === 'addProperties') { + Object.assign(state, action.extraData); + } + + if (action.hasOwnProperty('type') && action.type === 'removeProperties') { + for (const key of action.keysToRemove) { + delete state[key]; + } + } + + if (action.hasOwnProperty('type') && action.type === 'clear') { + const keys = Object.keys(state); + + for (const key of keys) { + delete state[key]; + } + } + } } module.exports = transformState;