From 4acd79dc9be14d3f67f3c6a674c57314ea9fd948 Mon Sep 17 00:00:00 2001 From: Maksym Borysenko Date: Sun, 30 Jul 2023 15:54:38 +0300 Subject: [PATCH 1/3] solved task --- src/transformState.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/transformState.js b/src/transformState.js index a1eaa0640..0187efd3f 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 act of actions) { + switch (act.type) { + case 'addProperties': + Object.assign(state, act.extraData); + break; + + case 'removeProperties': + for (const property of act.keysToRemove) { + delete state[property]; + } + break; + + case 'clear': + Object.keys(state).forEach(key => delete state[key]); + break; + } + }п } module.exports = transformState; From e5d0895d07186d24cebbd26ae6d1178834ee7d1d Mon Sep 17 00:00:00 2001 From: Maksym Borysenko Date: Sun, 30 Jul 2023 15:56:43 +0300 Subject: [PATCH 2/3] solved task --- src/transformState.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/transformState.js b/src/transformState.js index 0187efd3f..4194365a8 100644 --- a/src/transformState.js +++ b/src/transformState.js @@ -21,7 +21,7 @@ function transformState(state, actions) { Object.keys(state).forEach(key => delete state[key]); break; } - }п + } } module.exports = transformState; From 3e1068a6aa2a39536b1c276c4b9e35a30cb1030f Mon Sep 17 00:00:00 2001 From: Maksym Borysenko Date: Sun, 30 Jul 2023 19:32:08 +0300 Subject: [PATCH 3/3] fixing problems --- src/transformState.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/transformState.js b/src/transformState.js index 4194365a8..2946b89a1 100644 --- a/src/transformState.js +++ b/src/transformState.js @@ -5,14 +5,16 @@ * @param {Object[]} actions */ function transformState(state, actions) { - for (const act of actions) { - switch (act.type) { + for (const action of actions) { + const { type } = action; + + switch (type) { case 'addProperties': - Object.assign(state, act.extraData); + Object.assign(state, action.extraData); break; case 'removeProperties': - for (const property of act.keysToRemove) { + for (const property of action.keysToRemove) { delete state[property]; } break;