diff --git a/src/transformState.js b/src/transformState.js index a1eaa064..a3c68e11 100644 --- a/src/transformState.js +++ b/src/transformState.js @@ -1,11 +1,32 @@ 'use strict'; -/** - * @param {Object} state - * @param {Object[]} actions - */ + + @param {Object} state + @param {Object[]} actions + 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': + for (const key of keysToRemove) { + delete state[key]; + } + break; + + case 'clear': + for (const key in state) { + delete state[key]; + } + break; + } + } } module.exports = transformState;