Skip to content

Commit

Permalink
add task solution 2
Browse files Browse the repository at this point in the history
  • Loading branch information
edgergard committed Aug 3, 2023
1 parent b52ac24 commit 3c50b86
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/transformState.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,30 @@
* @param {Object[]} actions
*/
function transformState(state, actions) {
for (let i = 0; i < actions.length; i++) {
switch (actions[i].type) {
case 'addProperties':
for (const key in actions[i].extraData) {
state[key] = actions[i].extraData[key];
}
for (const action of actions) {
switch (action.type) {
case 'addProperties': {
Object.assign(state, action.extraData);
break;
}

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

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

default:
default: {
throw new Error('ERROR');
}
}
}
}
Expand Down

0 comments on commit 3c50b86

Please sign in to comment.