Skip to content

Commit

Permalink
solution
Browse files Browse the repository at this point in the history
  • Loading branch information
OlegMysko committed Dec 11, 2024
1 parent 7aa3e8a commit aa5921f
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/transformStateWithClones.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,25 @@
* @return {Object[]}
*/
function transformStateWithClones(state, actions) {
// write code here
const result = [];

let transClone = structuredClone(state);

for (const action of actions) {
if (action.type === 'removeProperties') {
for (const key of action.keysToRemove) {
delete transClone[key];
}
} else if (action.type === 'addProperties') {
transClone = { ...transClone, ...action.extraData };
} else if (action.type === 'clear') {
transClone = {};
}

result.push(structuredClone(transClone));
}

return result;
}

module.exports = transformStateWithClones;

0 comments on commit aa5921f

Please sign in to comment.