Skip to content

Commit

Permalink
make task solution
Browse files Browse the repository at this point in the history
  • Loading branch information
VvynnykV committed Feb 19, 2024
1 parent 8de408a commit 2adfe5c
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/transformState.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,28 @@
* @param {Object[]} actions
*/
function transformState(state, actions) {
// write code here
actions.forEach(action => {
switch (action.type) {
case 'clear': for (const key in state) {
delete state[key];
};
break;

case 'addProperties': Object.assign(state, action.extraData);
break;

case 'removeProperties': action.keysToRemove.forEach(key => {
if (state.hasOwnProperty(key)) {
delete state[key];
}
});
break;

default: return 'Fix mistake';
}
});

return state;
}

module.exports = transformState;

0 comments on commit 2adfe5c

Please sign in to comment.