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
57 changes: 46 additions & 11 deletions src/transformStateWithClones.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,48 @@
'use strict';

/**
* @param {Object} state
* @param {Object[]} actions
*
* @return {Object[]}
*/
function transformStateWithClones(state, actions) {
// write code here
// Додайте 'export' на початку
export function transformStateWithClones(state, actions) {
const history = [];
let currentState = { ...state };

for (const action of actions) {
// ... ваш код далі ...
}

return history;
}

module.exports = transformStateWithClones;
for (const action of actions) {
switch (action.type) {
case 'clear':
// Reset to an empty object
currentState = {};
break;

case 'addProperties':
// Merge current state with extraData using spread syntax
currentState = {
...currentState,
...action.extraData
};
break;

case 'removeProperties':
// Create a new copy to modify
const nextState = { ...currentState };
action.keysToRemove.forEach(key => {
delete nextState[key];
});
currentState = nextState;
break;

default:
// If an unknown action type is passed, we keep the state as is
break;
}

// Push a new clone of the current state into our history array
history.push({ ...currentState });
}

return history;


Loading