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..35b47bd68 100644 --- a/src/transformState.js +++ b/src/transformState.js @@ -5,7 +5,40 @@ * @param {Object[]} actions */ function transformState(state, actions) { - // write code here + for (const key of actions) { + + if (key.type === 'addProperties') { + add(state, key.extraData); + } + + if (key.type === 'clear') { + clear(state); + } + + if (key.type === 'removeProperties') { + remove(state, key.keysToRemove); + } + } } +const add = (state, obj) => { + for (const key in obj) { + state[key] = obj[key]; + } + + return state; +}; + +const clear = (state) => { + for (const key in state) { + delete state[key]; + } +}; + +const remove = (state, keys) => { + for (const key of keys) { + delete state[key]; + } +}; + module.exports = transformState;