From 5849e0a62494a442354dedda8c13dd8bcd871a52 Mon Sep 17 00:00:00 2001 From: Ivan Krylo Date: Sun, 16 Jul 2023 15:27:02 +0300 Subject: [PATCH 1/3] solution --- src/transformState.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/transformState.js b/src/transformState.js index a1eaa0640..000411622 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 action of actions) { + if (action.type === 'addProperties') { + Object.assign(state, action.extraData); + } + + if (action.type === 'clear') { + for (const key in state) { + delete state[key]; + } + } + + if (action.type === 'removeProperties') { + for (const keyToRemove of action.keysToRemove) { + delete state[keyToRemove]; + }; + } + } } module.exports = transformState; From bc3e135a7a26a51b803555fa52f18b4b2f030d4b Mon Sep 17 00:00:00 2001 From: Ivan Krylo Date: Sun, 16 Jul 2023 15:42:56 +0300 Subject: [PATCH 2/3] solution --- package.json | 2 +- src/transformState.js | 28 ++++++++++++++++------------ 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/package.json b/package.json index e83fa6dc7..55e4ae2de 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "license": "GPL-3.0", "devDependencies": { "@mate-academy/eslint-config": "*", - "@mate-academy/scripts": "^0.3.5", + "@mate-academy/scripts": "^1.2.8", "eslint": "^5.16.0", "eslint-plugin-jest": "^22.4.1", "eslint-plugin-node": "^8.0.1", diff --git a/src/transformState.js b/src/transformState.js index 000411622..03e312025 100644 --- a/src/transformState.js +++ b/src/transformState.js @@ -6,20 +6,24 @@ */ function transformState(state, actions) { for (const action of actions) { - if (action.type === 'addProperties') { - Object.assign(state, action.extraData); - } + switch (action.type) { + case 'addProperties': + Object.assign(state, action.extraData); + break; - if (action.type === 'clear') { - for (const key in state) { - delete state[key]; - } - } + case 'clear': + for (const key in state) { + delete state[key]; + }; + break; + + case 'removeProperties': + for (const keyToRemove of action.keysToRemove) { + delete state[keyToRemove]; + }; + break; - if (action.type === 'removeProperties') { - for (const keyToRemove of action.keysToRemove) { - delete state[keyToRemove]; - }; + default: return null; } } } From 59f6013de7a589a43c397e44020be438c836fa21 Mon Sep 17 00:00:00 2001 From: Ivan Krylo Date: Sun, 16 Jul 2023 16:01:32 +0300 Subject: [PATCH 3/3] solution --- src/transformState.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/transformState.js b/src/transformState.js index 03e312025..5eb215dbf 100644 --- a/src/transformState.js +++ b/src/transformState.js @@ -23,7 +23,7 @@ function transformState(state, actions) { }; break; - default: return null; + default: continue; } } }