Skip to content

Commit

Permalink
transformState solution
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtemSydun committed Oct 6, 2023
1 parent 8de408a commit 28d7245
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion src/transformState.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,32 @@
* @param {Object[]} actions
*/
function transformState(state, actions) {
// write code here
const addProp = 'addProperties';
const removeProp = 'removeProperties';
const clear = 'clear';

for (const action of actions) {
switch (action.type) {
case addProp:
for (const [key, value] of Object.entries(action.extraData)) {
state[key] = value;
}
break;

case removeProp:
for (const key of action.keysToRemove) {
delete state[key];
}
break;

case clear:
for (const key of Object.keys(state)) {
delete state[key];
}
}
}

return state;
}

module.exports = transformState;

0 comments on commit 28d7245

Please sign in to comment.