From 118cc49287002ddee3c739bf375680837de599d1 Mon Sep 17 00:00:00 2001 From: Olha Rypich Date: Sat, 15 Jul 2023 16:46:50 +0300 Subject: [PATCH] stateful-object --- src/transformState.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/transformState.js b/src/transformState.js index a1eaa0640..178bcd228 100644 --- a/src/transformState.js +++ b/src/transformState.js @@ -5,7 +5,23 @@ * @param {Object[]} actions */ function transformState(state, actions) { - // write code here + for (const action of actions) { + if (action.type === 'addProperties') { + Object.assign(state, action.extraData); + } + + if (action.type === 'removeProperties') { + for (const key of action.keysToRemove) { + delete state[key]; + } + } + + if (action.type === 'clear') { + for (const key in state) { + delete state[key]; + } + } + } } module.exports = transformState;