From 15f3cf73ac0404f99ab386a64c44601d80777309 Mon Sep 17 00:00:00 2001 From: Roman Perepelkin Date: Fri, 4 Aug 2023 13:07:15 +0300 Subject: [PATCH] Solution --- src/transformState.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/transformState.js b/src/transformState.js index a1eaa0640..f32c24f93 100644 --- a/src/transformState.js +++ b/src/transformState.js @@ -5,7 +5,25 @@ * @param {Object[]} actions */ function transformState(state, actions) { - // write code here + for (const obj of actions) { + if (obj.type === 'addProperties') { + Object.assign(state, obj.extraData); + } + + if (obj.type === 'removeProperties') { + for (const key of obj.keysToRemove) { + delete state[key]; + } + } + + if (obj.type === 'clear') { + for (const prop in state) { + delete state[prop]; + } + } + } + + return state; } module.exports = transformState;