Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add task solution #2617

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
33 changes: 32 additions & 1 deletion src/transformState.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,39 @@
* @param {Object} state
* @param {Object[]} actions
*/
const ADD_PROPERTIES = 'addProperties';
const REMOVE_PROPERTIES = 'removeProperties';
const CLEAR_ALL = 'clear';

function transformState(state, actions) {
// write code here
const stateHistory = [];
Copy link

Choose a reason for hiding this comment

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

you weren't prompted to track state history, but it's good idea 😄

Copy link
Author

Choose a reason for hiding this comment

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

so i keep this ;p


for (const order of actions) {
switch (order.type) {
case ADD_PROPERTIES:
Object.assign(state, order.extraData);
stateHistory.push(Object.assign({}, state));
break;

case REMOVE_PROPERTIES:
for (const remove of order.keysToRemove) {
delete state[remove];
}

stateHistory.push(Object.assign({}, state));
break;

case CLEAR_ALL:
for (const key in state) {
delete state[key];
}

stateHistory.push(Object.assign({}, state));
break;
}
}

return state;
}

module.exports = transformState;
Loading