From cc291e2c150293e78ce34a9c8d5d32c2ca5c7e17 Mon Sep 17 00:00:00 2001 From: Yura Panchyshyn Date: Fri, 31 Jan 2025 19:51:30 +0200 Subject: [PATCH] Solution --- src/transformStateWithClones.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/transformStateWithClones.js b/src/transformStateWithClones.js index 96d4f7e7e..f37275025 100644 --- a/src/transformStateWithClones.js +++ b/src/transformStateWithClones.js @@ -7,7 +7,25 @@ * @return {Object[]} */ function transformStateWithClones(state, actions) { - // write code here + let currentState = { ...state }; + const states = []; + + for (const action of actions) { + if (action.type === 'clear') { + currentState = {}; + } else if (action.type === 'addProperties') { + currentState = { ...currentState, ...action.extraData }; + } else if (action.type === 'removeProperties') { + currentState = { ...currentState }; + + for (const key of action.keysToRemove) { + delete currentState[key]; + } + } + states.push(currentState); + } + + return states; } module.exports = transformStateWithClones;