diff --git a/src/transformStateWithClones.js b/src/transformStateWithClones.js index 96d4f7e7e..d218acee8 100644 --- a/src/transformStateWithClones.js +++ b/src/transformStateWithClones.js @@ -7,7 +7,34 @@ * @return {Object[]} */ function transformStateWithClones(state, actions) { - // write code here + const states = []; + + let newState = { ...state }; + + actions.forEach((action) => { + switch (action.type) { + case 'clear': + newState = {}; + break; + + case 'addProperties': + newState = { ...newState, ...action.extraData }; + break; + + case 'removeProperties': + action.keysToRemove.forEach((key) => { + delete newState[key]; + }); + break; + + default: + break; + } + + states.push({ ...newState }); + }); + + return states; } module.exports = transformStateWithClones;