Skip to content

Commit

Permalink
resolved task
Browse files Browse the repository at this point in the history
  • Loading branch information
mykhailo-s committed Dec 5, 2024
1 parent 7aa3e8a commit b7607fa
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/transformStateWithClones.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,27 @@
* @return {Object[]}
*/
function transformStateWithClones(state, actions) {
// write code here
let stateClone = {...state};
let actionHistory = [];
for (const action of actions) {
switch (action.type) {
case 'addProperties':
stateClone = {...stateClone,...action.extraData}
break;
case 'removeProperties':
action.keysToRemove.forEach(key => {
delete stateClone[key];
});
break;
case 'clear':
stateClone = {};

break;
default:
}
actionHistory.push({...stateClone});
}
return actionHistory;
}

module.exports = transformStateWithClones;

0 comments on commit b7607fa

Please sign in to comment.