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