Skip to content

Commit

Permalink
Stateful object
Browse files Browse the repository at this point in the history
  • Loading branch information
stunnerboyone committed Jul 28, 2023
1 parent 8de408a commit ea914e8
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 @@ -4,8 +4,30 @@
* @param {Object} state
* @param {Object[]} actions
*/

function transformState(state, actions) {
// write code here
for (let i = 0; i < actions.length; i++) {
switch (actions[i].type) {
case 'addProperties':
Object.assign(state, { ...actions[i].extraData });
break;
case 'removeProperties':
for (let j = 0; j < actions[i].keysToRemove.length; j++) {
delete state[actions[i].keysToRemove[j]];
}
break;
case 'clear':
for (const key in state) {
delete state[key];
}
break;
default:
continue;
}
}

return state;
}

module.exports = transformState;

0 comments on commit ea914e8

Please sign in to comment.