Skip to content

Commit

Permalink
transformState
Browse files Browse the repository at this point in the history
  • Loading branch information
olena-nimakova committed Sep 2, 2023
1 parent 8de408a commit 9be9f3e
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/transformState.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,29 @@
* @param {Object[]} actions
*/
function transformState(state, actions) {
// write code here
for (let i = 0; i < actions.length; i++) {
if (actions[i].type === 'addProperties') {
Object.assign(state, actions[i].extraData);
}

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

if (actions[i].type === 'clear') {
for (const key in state) {
if (state.hasOwnProperty(key)) {
delete state[key];
}
}
}
}

return state;
}

module.exports = transformState;

0 comments on commit 9be9f3e

Please sign in to comment.