Skip to content

Commit

Permalink
stateful-object
Browse files Browse the repository at this point in the history
  • Loading branch information
olha-rypich committed Jul 15, 2023
1 parent 8de408a commit 118cc49
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) {
if (action.type === 'addProperties') {
Object.assign(state, action.extraData);
}

if (action.type === 'removeProperties') {
for (const key of action.keysToRemove) {
delete state[key];
}
}

if (action.type === 'clear') {
for (const key in state) {
delete state[key];
}
}
}
}

module.exports = transformState;

0 comments on commit 118cc49

Please sign in to comment.