From 91d51f737e73f16a37bb358f86017f41fbcef365 Mon Sep 17 00:00:00 2001 From: Oleksandr Date: Tue, 23 Jan 2024 15:39:48 +0200 Subject: [PATCH] Solution --- src/transformState.js | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/transformState.js b/src/transformState.js index a1eaa064..4a7147bc 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) { + switch (action.type) { + case 'addProperties': + Object.assign(state, action.extraData); + break; + + case 'removeProperties': + for (const key of action.keysToRemove) { + if (state.hasOwnProperty(key)) { + delete state[key]; + } + } + break; + + case 'clear': + for (const key in state) { + delete state[key]; + } + break; + + default: + throw new Error('Type not supported'); + } + } } module.exports = transformState;