Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion src/transformStateWithClones.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,31 @@
* @return {Object[]}
*/
function transformStateWithClones(state, actions) {
// write code here
const history = [];
let currentState = { ...state };

for (const action of actions) {
switch (action.type) {
case 'addProperties':
Object.assign(currentState, action.extraData);
break;

case 'removeProperties':
for (const key of action.keysToRemove) {
delete currentState[key];
}
break;

case 'clear':
currentState = {};
break;
default:
return 'Erro';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This return statement causes the function to exit immediately with a string value. However, the function is documented to return an array of objects (Object[]), so returning a string here is incorrect.

For an unknown action type, the function should probably ignore it and continue processing the rest of the actions. A break statement would be more appropriate here to achieve that.

}
history.push({ ...currentState });
}

return history;
}

module.exports = transformStateWithClones;