From b7ddd0da1e5ca33df2c4d8c96a4af3d98085202e Mon Sep 17 00:00:00 2001 From: Tobiasz Nowak Date: Thu, 30 Nov 2023 13:24:25 +0100 Subject: [PATCH] Solution --- .github/workflows/test.yml | 2 +- package.json | 2 +- src/transformState.js | 22 +++++++++++++++++++++- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index def73e604..e80632740 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -11,7 +11,7 @@ jobs: strategy: matrix: - node-version: [12.x] + node-version: [14.x] steps: - uses: actions/checkout@v2 diff --git a/package.json b/package.json index e83fa6dc7..f2cf54e90 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.12", "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 a1eaa0640..5584f578a 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;