From c4a4423fee60d1a8bd5e5953874cd12b03df0a62 Mon Sep 17 00:00:00 2001 From: LabPetro Date: Thu, 5 Oct 2023 16:23:11 +0300 Subject: [PATCH] Solution --- package.json | 2 +- src/transformState.js | 25 ++++++++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index e83fa6dc..55e4ae2d 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 a1eaa064..e1884477 100644 --- a/src/transformState.js +++ b/src/transformState.js @@ -5,7 +5,30 @@ * @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; + + default: + return 'Error: Type Unknown'; + } + } } module.exports = transformState;