From a6fc897b007e71741db12ef512b9b915f6367686 Mon Sep 17 00:00:00 2001 From: DenisNosov22 Date: Fri, 26 Dec 2025 15:52:39 +0200 Subject: [PATCH 1/2] js test too --- src/transformStateWithClones.js | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/transformStateWithClones.js b/src/transformStateWithClones.js index 96d4f7e7e..997959600 100644 --- a/src/transformStateWithClones.js +++ b/src/transformStateWithClones.js @@ -7,7 +7,35 @@ * @return {Object[]} */ function transformStateWithClones(state, actions) { - // write code here + const history = []; + let currentState = { ...state }; + + for (const action of actions) { + if (action.type === 'clear') { + currentState = {}; + } + + if (action.type === 'addProperties') { + currentState = { + ...currentState, + ...action.extraData, + }; + } + + if (action.type === 'removeProperties') { + const nextState = { ...currentState }; + + for (const key of action.keysToRemove) { + delete nextState[key]; + } + + currentState = nextState; + } + + history.push(currentState); + } + + return history; } module.exports = transformStateWithClones; From e6d4ecba407a89c9b3c7c1d77c38e597b27fd745 Mon Sep 17 00:00:00 2001 From: DenisNosov22 Date: Fri, 26 Dec 2025 16:02:30 +0200 Subject: [PATCH 2/2] js test * --- src/transformStateWithClones.js | 40 +++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/src/transformStateWithClones.js b/src/transformStateWithClones.js index 997959600..13cb01c8d 100644 --- a/src/transformStateWithClones.js +++ b/src/transformStateWithClones.js @@ -11,25 +11,31 @@ function transformStateWithClones(state, actions) { let currentState = { ...state }; for (const action of actions) { - if (action.type === 'clear') { - currentState = {}; - } - - if (action.type === 'addProperties') { - currentState = { - ...currentState, - ...action.extraData, - }; - } - - if (action.type === 'removeProperties') { - const nextState = { ...currentState }; - - for (const key of action.keysToRemove) { - delete nextState[key]; + switch (action.type) { + case 'clear': + currentState = {}; + break; + + case 'addProperties': + currentState = { + ...currentState, + ...action.extraData, + }; + break; + + case 'removeProperties': { + const nextState = { ...currentState }; + + for (const key of action.keysToRemove) { + delete nextState[key]; + } + + currentState = nextState; + break; } - currentState = nextState; + default: + throw new Error(`Unknown action type: ${action.type}`); } history.push(currentState);