Skip to content

Commit

Permalink
Solution
Browse files Browse the repository at this point in the history
  • Loading branch information
oshapkun committed Jul 17, 2023
1 parent 8de408a commit 52579fa
Show file tree
Hide file tree
Showing 2 changed files with 37 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.8",
"eslint": "^5.16.0",
"eslint-plugin-jest": "^22.4.1",
"eslint-plugin-node": "^8.0.1",
Expand Down
37 changes: 36 additions & 1 deletion src/transformState.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,42 @@
* @param {Object[]} actions
*/
function transformState(state, actions) {
// write code here
for (const action of actions) {
const { type } = action;

switch (type) {
case 'addProperties': {
const { extraData } = action;

for (const key in extraData) {
state[key] = extraData[key];
}
break;
}

case 'removeProperties': {
const { keysToRemove } = action;

for (const key of keysToRemove) {
if (state.hasOwnProperty(key)) {
delete state[key];
}
}
break;
}

case 'clear': {
for (const key in state) {
delete state[key];
}
break;
}

default: {
throw new Error(`Unknown action type: ${type}`);
}
}
}
}

module.exports = transformState;

0 comments on commit 52579fa

Please sign in to comment.