Skip to content

Commit

Permalink
feat: provides with solution
Browse files Browse the repository at this point in the history
  • Loading branch information
kkrasnoshchok committed Jan 10, 2024
1 parent 8de408a commit 058c958
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
29 changes: 28 additions & 1 deletion src/transformState.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,34 @@
* @param {Object[]} actions
*/
function transformState(state, actions) {
// write code here
if (Array.isArray(actions)) {
for (const action of actions) {
actionsObserver(state, action);
}

return;
}
actionsObserver(state, actions);
}

module.exports = transformState;

const actionsObserver = (state, action) => {
switch (action.type) {
case 'addProperties':
Object.assign(state, action.extraData);
break;
case 'removeProperties':
for (const key of action.keysToRemove) {
delete state[key];
}
break;
case 'clear':
for (const key in state) {
delete state[key];
}
break;
default:
break;
}
};

0 comments on commit 058c958

Please sign in to comment.