Skip to content

Commit

Permalink
solving task
Browse files Browse the repository at this point in the history
  • Loading branch information
Kasiacoder committed Dec 9, 2024
1 parent 7aa3e8a commit e780875
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions src/transformStateWithClones.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,30 @@
* @return {Object[]}
*/
function transformStateWithClones(state, actions) {
// write code here
}
const stateHistory = [];
let currentState = { ...state };

actions.forEach((action) => {
switch (action.type) {
case 'clear':
currentState = {};
break;
case 'addProperties':
currentState = { ...currentState, ...action.extraData };
break;
case 'removeProperties':
action.keysToRemove.forEach((key) => {
delete currentState[key];
});
break;
default:
throw new Error(`Unknown action type: ${action.type}`);
}
stateHistory.push({ ...currentState });
});

return stateHistory;
}


module.exports = transformStateWithClones;

0 comments on commit e780875

Please sign in to comment.