From 2adfe5c601fa9c3e6087bb81f144bb88418d9bbf Mon Sep 17 00:00:00 2001 From: Volodymyr Vynnyk Date: Mon, 19 Feb 2024 17:10:50 +0200 Subject: [PATCH] make task solution --- src/transformState.js | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/transformState.js b/src/transformState.js index a1eaa0640..65353bb4d 100644 --- a/src/transformState.js +++ b/src/transformState.js @@ -5,7 +5,28 @@ * @param {Object[]} actions */ function transformState(state, actions) { - // write code here + actions.forEach(action => { + switch (action.type) { + case 'clear': for (const key in state) { + delete state[key]; + }; + break; + + case 'addProperties': Object.assign(state, action.extraData); + break; + + case 'removeProperties': action.keysToRemove.forEach(key => { + if (state.hasOwnProperty(key)) { + delete state[key]; + } + }); + break; + + default: return 'Fix mistake'; + } + }); + + return state; } module.exports = transformState;