Skip to content

Commit

Permalink
Solution
Browse files Browse the repository at this point in the history
  • Loading branch information
IgorDuganets1 committed Feb 19, 2024
1 parent 8de408a commit da4ad71
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/transformState.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,28 @@
*/
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':
for (const key of action.keysToRemove) {
if (state.hasOwnProperty(key)) {
delete state[key];
}
}
break;
case 'clear':
for (const key in state) {
delete state[key];
}
break;
default:
// Do nothing for unknown action types
break;
}
}
}

module.exports = transformState;

0 comments on commit da4ad71

Please sign in to comment.