Skip to content

Commit

Permalink
Solution
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaliipp committed Aug 11, 2023
1 parent 8de408a commit eddb04b
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/transformState.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,31 @@
*/
function transformState(state, actions) {
// write code here
for (const action of actions) {
const { type, extraData, keysToRemove } = action;

switch (type) {
case 'addProperties':
Object.assign(state, extraData);

break;

case 'removeProperties':
keysToRemove.forEach((key) => delete state[key]);

break;

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

break;

default:
throw new Error('Invalid action type');
}
}

return state;
}

module.exports = transformState;

0 comments on commit eddb04b

Please sign in to comment.