diff --git a/src/transformState.js b/src/transformState.js index a1eaa064..2f9ae512 100644 --- a/src/transformState.js +++ b/src/transformState.js @@ -1,11 +1,36 @@ -'use strict'; +"use strict"; -/** - * @param {Object} state - * @param {Object[]} actions - */ function transformState(state, actions) { - // write code here + for (const action of actions) { + const { type } = action; + + switch (type) { + case "addProperties": + const { extraData } = action; + if (extraData) { + Object.assign(state, extraData); + } + break; + + case "removeProperties": + const { keysToRemove } = action; + if (keysToRemove) { + for (const key of keysToRemove) { + delete state[key]; + } + } + break; + + case "clear": + Object.keys(state).forEach((key) => { + delete state[key]; + }); + break; + + default: + break; + } + } } module.exports = transformState;