Skip to content

Commit

Permalink
Solution
Browse files Browse the repository at this point in the history
  • Loading branch information
RomanPerepelkin committed Aug 4, 2023
1 parent 8de408a commit 15f3cf7
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/transformState.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,25 @@
* @param {Object[]} actions
*/
function transformState(state, actions) {
// write code here
for (const obj of actions) {
if (obj.type === 'addProperties') {
Object.assign(state, obj.extraData);
}

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

if (obj.type === 'clear') {
for (const prop in state) {
delete state[prop];
}
}
}

return state;
}

module.exports = transformState;

0 comments on commit 15f3cf7

Please sign in to comment.