From aa5921faacc436ceade217263f423502167e4240 Mon Sep 17 00:00:00 2001 From: Oleh Mysko Date: Wed, 11 Dec 2024 18:29:43 +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..9287a354a 100644 --- a/src/transformStateWithClones.js +++ b/src/transformStateWithClones.js @@ -7,7 +7,25 @@ * @return {Object[]} */ function transformStateWithClones(state, actions) { - // write code here + const result = []; + + let transClone = structuredClone(state); + + for (const action of actions) { + if (action.type === 'removeProperties') { + for (const key of action.keysToRemove) { + delete transClone[key]; + } + } else if (action.type === 'addProperties') { + transClone = { ...transClone, ...action.extraData }; + } else if (action.type === 'clear') { + transClone = {}; + } + + result.push(structuredClone(transClone)); + } + + return result; } module.exports = transformStateWithClones;