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

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

solution #1618

wants to merge 4 commits into from

Conversation

00Mass00
Copy link

Copy link

@dffUqp dffUqp 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:smiley:

{`My name is ${name}`}
</h2>

{age && <p className="Person__age">{`I am ${age}`}</p>}
Copy link

Choose a reason for hiding this comment

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

Suggested change
{age && <p className="Person__age">{`I am ${age}`}</p>}
{age && (
<p className="Person__age">{`I am ${age}`}</p>
)}

Comment on lines 30 to 31
? `${partnerName} is my ${getPartner()}`
: getPartner()
Copy link

Choose a reason for hiding this comment

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

I think will be better to refactor this solution and remove getPartner function.

Instead of calling getPartner the second time, we can use 'I am not married' string.

@00Mass00 00Mass00 requested a review from dffUqp August 22, 2023 19:28
: HUSBAND;
}

return 'I am not married';

Choose a reason for hiding this comment

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

'I'm not married' doesn't sound like partner, I'd prefer to create variable and use ternary

@00Mass00 00Mass00 requested a review from tiserett August 22, 2023 19:46
Copy link

@roman-mirzoian roman-mirzoian 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 👍

const MALE = 'm';
const WIFE = 'wife';
const HUSBAND = 'husband';
const NOT_MARRIED_PERSON = 'I am not married';

Choose a reason for hiding this comment

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

Suggested change
const NOT_MARRIED_PERSON = 'I am not married';
const NOT_MARRIED_PERSON_MESSAGE = 'I am not married';

Comment on lines 6 to 43
export const Person = ({ person }) => {
const {
name,
age,
sex,
isMarried,
partnerName,
} = person;

const getPartner = () => {
if (isMarried) {
return sex === MALE
? WIFE
: HUSBAND;
}

return NOT_MARRIED_PERSON;
};

return (
<section className="Person">
<h2 className="Person__name">
{`My name is ${name}`}
</h2>

{age && (
<p className="Person__age">{`I am ${age}`}</p>
)}

<p className="Person__partner">
{partnerName
? `${partnerName} is my ${getPartner()}`
: NOT_MARRIED_PERSON
}
</p>
</section>
);
};

Choose a reason for hiding this comment

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

Now everything is written correctly, but I offer a more optimized version:

Suggested change
export const Person = ({ person }) => {
const {
name,
age,
sex,
isMarried,
partnerName,
} = person;
const getPartner = () => {
if (isMarried) {
return sex === MALE
? WIFE
: HUSBAND;
}
return NOT_MARRIED_PERSON;
};
return (
<section className="Person">
<h2 className="Person__name">
{`My name is ${name}`}
</h2>
{age && (
<p className="Person__age">{`I am ${age}`}</p>
)}
<p className="Person__partner">
{partnerName
? `${partnerName} is my ${getPartner()}`
: NOT_MARRIED_PERSON
}
</p>
</section>
);
};
const getPartner = (isMarried) => {
if (isMarried) {
return sex === MALE
? WIFE
: HUSBAND;
}
return NOT_MARRIED_PERSON_MESSAGE;
};
export const Person = ({ person }) => {
const {
name,
age,
sex,
isMarried,
partnerName,
} = person;
const partnerInfo = partnerName
? `${partnerName} is my ${getPartner(isMarried)}`
: NOT_MARRIED_PERSON_MESSAGE;
return (
<section className="Person">
<h2 className="Person__name">
{`My name is ${name}`}
</h2>
{age && (
<p className="Person__age">{`I am ${age}`}</p>
)}
<p className="Person__partner">
{ partnerInfo }
</p>
</section>
);
};

Copy link
Author

Choose a reason for hiding this comment

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

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