diff --git a/src/transformStateWithClones.js b/src/transformStateWithClones.js index 96d4f7e7e..8c7ff9340 100644 --- a/src/transformStateWithClones.js +++ b/src/transformStateWithClones.js @@ -8,6 +8,38 @@ */ function transformStateWithClones(state, actions) { // write code here + const history = []; + let currentState = state; + + for (const action of actions) { + let nextState; + + switch (action.type) { + case 'clear': + nextState = {}; + break; + + case 'addProperties': + nextState = { ...currentState, ...action.extraData }; + break; + + case 'removeProperties': + nextState = { ...currentState }; + + for (const key of action.keysToRemove) { + delete nextState[key]; + } + break; + + default: + nextState = { ...currentState }; + } + + history.push(nextState); + currentState = nextState; + } + + return history; } module.exports = transformStateWithClones;