From 2d4e81feb6491791ebcd948ecb0a39b92b67ac39 Mon Sep 17 00:00:00 2001 From: Vadym Panchenko Date: Sat, 19 Aug 2023 16:57:29 +0300 Subject: [PATCH] add task solution --- src/transformState.js | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/transformState.js b/src/transformState.js index a1eaa064..5584f578 100644 --- a/src/transformState.js +++ b/src/transformState.js @@ -5,7 +5,27 @@ * @param {Object[]} actions */ function transformState(state, actions) { - // write code here + for (const action of actions) { + const { type, extraData, keysToRemove } = action; + + switch (type) { + case 'addProperties': + Object.assign(state, extraData); + break; + + case 'removeProperties': + for (const key of keysToRemove) { + delete state[key]; + } + break; + + case 'clear': + for (const key in state) { + delete state[key]; + } + break; + } + } } module.exports = transformState;