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

Task solution #2827

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

Conversation

kseniia-chepur
Copy link

No description provided.

@@ -7,7 +7,43 @@
* @return {Object[]}
*/
function transformStateWithClones(state, actions) {
// write code here
const statesArray = [];

Choose a reason for hiding this comment

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

Suggested change
const statesArray = [];
const statesArray = [];
const stateCopy = { ...state };

// write code here
const statesArray = [];

for (let i = 0; i < actions.length; i++) {

Choose a reason for hiding this comment

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

you can just use for of

Suggested change
for (let i = 0; i < actions.length; i++) {
for (const action of actions)) {

const statesArray = [];

for (let i = 0; i < actions.length; i++) {
switch (actions[i].type) {

Choose a reason for hiding this comment

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

Suggested change
switch (actions[i].type) {
switch (action.type) {

Comment on lines 15 to 19
const currentState = i ? { ...statesArray[i - 1] } : { ...state };

Object.assign(currentState, actions[i].extraData);
statesArray.push(currentState);
break;

Choose a reason for hiding this comment

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

  1. no needs to update state at each case
  2. no needs to push updates at each case
  3. apply similar solution to cases below
Suggested change
const currentState = i ? { ...statesArray[i - 1] } : { ...state };
Object.assign(currentState, actions[i].extraData);
statesArray.push(currentState);
break;
Object.assign(stateCopy, action.extraData);
break;

}

default: throw new Error('Invalid action type');
}

Choose a reason for hiding this comment

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

Suggested change
}
}
statesArray.push({ ...stateCopy });

@kseniia-chepur
Copy link
Author

Fixed

Copy link

@volodymyr-soltys97 volodymyr-soltys97 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 👍
Let's improve your code

Comment on lines 13 to 14
for (const action of actions) {
switch (action.type) {

Choose a reason for hiding this comment

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

Try to use a destruction for action

Suggested change
for (const action of actions) {
switch (action.type) {
for (const action of actions) {
const { type, ....... } = action;
switch (type) {


for (const action of actions) {
switch (action.type) {
case 'addProperties': {

Choose a reason for hiding this comment

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

Consider will be better if you create a variables for these words and use them everywhere

Copy link

@VitaliyBondarenko1982 VitaliyBondarenko1982 left a comment

Choose a reason for hiding this comment

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

Well done

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