Skip to content

Commit

Permalink
solution
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrii-OttO committed Oct 4, 2023
1 parent 4244c2f commit 3bbf250
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/transformStateWithClones.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,29 @@
* @return {Object[]}
*/
function transformStateWithClones(state, actions) {
// write code here
let newObj = { ...state };
const result = [];

for (const item of actions) {
if (item.type === 'addProperties') {
newObj = {
...newObj, ...item.extraData,
};
}

if (item.type === 'removeProperties') {
for (const key of item.keysToRemove) {
delete newObj[key];
}
}

if (item.type === 'clear') {
newObj = {};
}
result.push({ ...newObj });
}

return result;
}

module.exports = transformStateWithClones;

0 comments on commit 3bbf250

Please sign in to comment.