From 2898a790cfa74bb390764a25641e200a2e797eba Mon Sep 17 00:00:00 2001 From: Olha Momot Date: Wed, 2 Aug 2023 15:39:43 +0300 Subject: [PATCH] add task solution --- src/transformState.js | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/transformState.js b/src/transformState.js index a1eaa0640..c1bb13209 100644 --- a/src/transformState.js +++ b/src/transformState.js @@ -5,7 +5,30 @@ * @param {Object[]} actions */ function transformState(state, actions) { - // write code here + for (const action of actions) { + const { type } = action; + + switch (type) { + case 'addProperties': + Object.assign(state, action.extraData); + break; + + case 'removeProperties': + action.keysToRemove.forEach(key => { + delete state[key]; + }); + break; + + case 'clear': + Object.keys(state).forEach(key => delete state[key]); + break; + + default: + throw new Error(); + } + } + + return state; } module.exports = transformState;