-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
base: master
Are you sure you want to change the base?
Solution #4094
Conversation
There was a problem hiding this 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.
src/transformStateWithClones.js
Outdated
}); | ||
break; | ||
default: | ||
throw new Error('Unknown action Type: ${action.type}'); |
There was a problem hiding this comment.
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.
There was a problem hiding this 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!
src/transformStateWithClones.js
Outdated
currentState = { ...currentState, ...action.extraData }; | ||
break; | ||
case 'removeProperties': | ||
currentState = { ...currentState }; |
There was a problem hiding this comment.
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
src/transformStateWithClones.js
Outdated
}); | ||
break; | ||
default: | ||
throw new Error('Unknown action Type: ${action.type}'); |
There was a problem hiding this comment.
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
There was a problem hiding this 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}`); |
There was a problem hiding this comment.
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 => { |
There was a problem hiding this comment.
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': |
There was a problem hiding this comment.
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:
No description provided.