Skip to content

Commit

Permalink
Implement changes
Browse files Browse the repository at this point in the history
  • Loading branch information
natalia-matash committed Dec 27, 2023
1 parent aeb9da7 commit aa77cac
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions src/transformState.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,33 @@
* @param {Object[]} actions
*/
function transformState(state, actions) {
// write code here
for (const action of actions) {
if (action.type === 'clear') {
for (const s in state) {
delete state[s];
const { type, extraData, keysToRemove } = action;

switch (true) {
case type === 'clear': {
for (const s in state) {
delete state[s];
}
break;
}
}

if (action.type === 'addProperties') {
Object.assign(state, action.extraData);
}
case type === 'addProperties': {
Object.assign(state, extraData);
break;
}

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

default:
return 'Unexpected acrion';
};
};

return state;
}
Expand Down

0 comments on commit aa77cac

Please sign in to comment.