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 #4094

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

Solution #4094

wants to merge 2 commits into from

Conversation

wallacesaito95
Copy link

No description provided.

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

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

Your implementation is almost there, but there are a couple of critical issues that need to be addressed to meet the task requirements. Firstly, ensure that the states.push(currentState); statement is placed outside of the switch block to correctly record the state after processing all actions. Secondly, correct the error message in the default case to use backticks for proper template literal syntax. Once these are fixed, your solution will be in great shape! Keep up the good work! 😊

✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨

🔄 Fix the issues, commit the changes, and then re-request my review using the Re-request review button in the Reviewers tab.

});
break;
default:
throw new Error('Unknown action Type: ${action.type}');

Choose a reason for hiding this comment

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

The error message uses template literals incorrectly. It should be throw new Error(Unknown action Type: ${action.type}); with backticks instead of single quotes.

src/transformStateWithClones.js Show resolved Hide resolved
Copy link

@pedro-ruas pedro-ruas left a comment

Choose a reason for hiding this comment

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

Just two line changes and it will be perfect!

currentState = { ...currentState, ...action.extraData };
break;
case 'removeProperties':
currentState = { ...currentState };

Choose a reason for hiding this comment

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

This line is unnecessary as you are just re-creating the object as it already is

});
break;
default:
throw new Error('Unknown action Type: ${action.type}');

Choose a reason for hiding this comment

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

For this to work, instead of single quotes, you should use backtick " ` ", if not, it will literally write ${action.type} and not it's value

src/transformStateWithClones.js Show resolved Hide resolved
Copy link

@joaorpereira joaorpereira left a comment

Choose a reason for hiding this comment

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

create addProperties method

});
break;
default:
throw new Error(`Unknown action Type: ${action.type}`);

Choose a reason for hiding this comment

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

remove this line

const states = [];
let currentState = { ...state };

actions.forEach(action => {

Choose a reason for hiding this comment

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

This task requires 3 methods:
'clear', 'addProperties', 'removeProperties'

You wrote just two:
'clear', 'addProperties'

Pay attention on the properties names, as addproperties is different than addProperties

case 'clear':
currentState = {};
break;
case 'addproperties':

Choose a reason for hiding this comment

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

this is not the addproperties, but the removeProperties

case 'removeProperties':
        currentState = { ...currentState };

        action.keysToRemove.forEach((key) => {
          delete currentState[key];
        });
        break;
      default:

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.

4 participants