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

solution #2682

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Conversation

vladyslav-svorin
Copy link

No description provided.

Copy link

@loralevitska loralevitska left a comment

Choose a reason for hiding this comment

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

Good job! There are things that should be fixed:

break;

case 'removeProperties':
if (actions[i].keysToRemove !== undefined) {

Choose a reason for hiding this comment

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

There's no need for checking if 'keysToRemove' is undefined. If it's undefined, the later for loop just won't execute.

@@ -5,7 +5,34 @@
* @param {Object[]} actions
*/
function transformState(state, actions) {
// write code here
for (let i = 0; i < actions.length; i++) {
const mainAction = actions[i].type;

Choose a reason for hiding this comment

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

Instead of traditional for loop, use of 'for...of' loop is recommended for better readability when iterating over an array.

@@ -5,7 +5,34 @@
* @param {Object[]} actions
*/
function transformState(state, actions) {
// write code here
for (let i = 0; i < actions.length; i++) {
const mainAction = actions[i].type;

Choose a reason for hiding this comment

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

Destructure action
const { type, extraData, keysToRemove } = actions[i]

Copy link

@VitaliyBodnar VitaliyBodnar left a comment

Choose a reason for hiding this comment

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

Almost done!

break;

case 'removeProperties':
const toRemove = keysToRemove;

Choose a reason for hiding this comment

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

this variable is reduntant here

Comment on lines 27 to 29
for (let j = 0; j < toRemove.length; j++) {
delete state[toRemove[j]];
}

Choose a reason for hiding this comment

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

don't see any sense in using for loop, better to use for of or forEach here

Copy link

@polosanya polosanya left a comment

Choose a reason for hiding this comment

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

One small but important fix left 🙏

src/transformState.js Show resolved Hide resolved
const { type, extraData, keysToRemove } = action;

switch (type) {
case 'clear':
Copy link

Choose a reason for hiding this comment

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

Move all cases to the object.

Example of usage:
case ActionType.Clear:

Copy link

@VitaliyBodnar VitaliyBodnar left a comment

Choose a reason for hiding this comment

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

Good job!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants