Skip to content

Commit

Permalink
Complite the task
Browse files Browse the repository at this point in the history
  • Loading branch information
AndruhaMan committed Jul 12, 2023
1 parent 8de408a commit 2d0f521
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/transformState.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,23 @@
* @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 'removeProperties':
action.keysToRemove.forEach((key) => delete state[key]);
break;

case 'clear':
Object.keys(state).forEach((key) => delete state[key]);
break;

default:
}
}
}

module.exports = transformState;

0 comments on commit 2d0f521

Please sign in to comment.