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 a1eaa0640..5eb215dbf 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) { + switch (action.type) { + case 'addProperties': + Object.assign(state, action.extraData); + break; + + case 'clear': + for (const key in state) { + delete state[key]; + }; + break; + + case 'removeProperties': + for (const keyToRemove of action.keysToRemove) { + delete state[keyToRemove]; + }; + break; + + default: continue; + } + } } module.exports = transformState;