Skip to content

Commit

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

switch (type) {
case 'addProperties':
for (const key in extraData) {
state[key] = extraData[key];
}
break;

case 'removeProperties':
if (keysToRemove) {
for (const key of keysToRemove) {
if (state.hasOwnProperty(key)) {
delete state[key];
}
}
}
break;

case 'clear':
for (const key in state) {
delete state[key];
}
break;

default:
throw new Error(`Unknown action type: ${type}`);
}
}
}

module.exports = transformState;

0 comments on commit 561c80c

Please sign in to comment.