diff --git a/src/transformStateWithClones.js b/src/transformStateWithClones.js index 96d4f7e7e..1739b0bdd 100644 --- a/src/transformStateWithClones.js +++ b/src/transformStateWithClones.js @@ -7,7 +7,36 @@ * @return {Object[]} */ function transformStateWithClones(state, actions) { - // write code here + const states = []; + let currentState = { ...state }; + + for (const action of actions) { + switch (action.type) { + case 'clear': + currentState = {}; + break; + case 'addProperties': + currentState = { + ...currentState, + ...action.extraData, + }; + break; + case 'removeProperties': + currentState = Object.keys(currentState) + .filter((key) => !action.keysToRemove.includes(key)) + .reduce((newState, key) => { + newState[key] = currentState[key]; + + return newState; + }, {}); + break; + default: + break; + } + states.push({ ...currentState }); + } + + return states; } module.exports = transformStateWithClones;