Skip to content

Commit

Permalink
all tests pass
Browse files Browse the repository at this point in the history
  • Loading branch information
aniashev committed Jul 18, 2023
1 parent 8de408a commit 76357e9
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/transformState.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,27 @@
* @param {Object[]} actions
*/
function transformState(state, actions) {
// write code here
for (let i = 0; i < actions.length; i++) {
const actionType = actions[i].type;

if (actionType === 'addProperties') {
Object.assign(state, actions[i].extraData);
} else if (actionType === 'removeProperties') {
const keysToRemove = actions[i].keysToRemove;

for (const key of keysToRemove) {
if (state.hasOwnProperty(key)) {
delete state[key];
}
}
} else if (actionType === 'clear') {
for (const key in state) {
delete state[key];
}
}
}

return state;
}

module.exports = transformState;

0 comments on commit 76357e9

Please sign in to comment.