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

A tiny JS world #443

Merged
merged 10 commits into from
Sep 8, 2022
Merged

A tiny JS world #443

merged 10 commits into from
Sep 8, 2022

Conversation

unabyband
Copy link
Contributor

A tiny JS world

Demo |
Code base

The code is submitted in a dedicated feature branch.

Only code files are submitted.

Please, review.

@unabyband unabyband changed the title Adding index.js A tiny JS world Sep 5, 2022
@github-actions
Copy link

github-actions bot commented Sep 5, 2022

Hey!

Congratulations on your PR! 😎😎😎

Let's do some self-checks to fix most common issues and to make some improvements to the code before reviewers put their hands on the code.

Go through the requirements/most common mistakes listed/linked below and fix the code as appropriate.

If you have any questions to requirements/common mistakes feel free asking them here or in Students' chat.

When you genuinely believe you are done put a comment stating that you have completed self-checks and fixed code accordingly.

Also, be aware, that if you would silently ignore this recommendation, a mentor can think that you are still working on fixes. And your PR will not be reviewed. 😒

A Tiny JS World -- (pre-OOP) exercise check list

Relates to Object-Oriented JavaScript task.

Check-list - definition of done

  • Code is DRY, which means that whenever you see a pattern in your code those should be eliminated as much as possible. Examples:
    • print(dog); print(cat); etc ... should be refactored employing Array.forEach as the least
    • `${obj.legs}; ${obj.name}; etc...` (yes, strings are also code) must be refactored employing appropriate Array methods
  • Object methods like keys, values, entries shouldn't be used when a particular order is required as these do not guarantee any particular order of keys/values. Same refers to for...of and for...in when applied to objects.
    Hint: List explicitly the properties used to form an object presentation string.
  • Men and women belong to the same biological species.
  • ES6 class or prototype-based OO syntax aren't used.

Universal recommendations:

  • Give variables and functions meaningful names. Avoid generic names like item, element, key, object, array or their variations. Exception: helper functions that are specifically and intentionally designed to be multipurpose.
  • Function names should start with a verb as they denote actions; variables are normally nouns; boolean variables/functions start with is, does, has etc; variable containing multiple entities and functions returning lists contain entity name in plural form.
  • Have consistent code style and formatting. Employ Prettier to do all dirty work for you.
  • Use common sense or seek for an advice whenever requirements look ambiguous or unclear.

Also take a note of the requirements above and follow them in all your future projects.

By the way, you may proceed to the next task before this one is reviewed and merged.

Sincerely yours,
Submissions Kottachecker 😺

@OleksiyRudenko
Copy link
Member

@unabyband please double check what the bot asked you to do.

@unabyband
Copy link
Contributor Author

Double check is done!

Copy link
Member

@OleksiyRudenko OleksiyRudenko left a comment

Choose a reason for hiding this comment

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

@unabyband good job!
Let's polish it.

// var test = man;
// test.saying = "<h2>Where's the money, Lebowski?</h2>";

function printInhabitants(inhabitant) {
Copy link
Member

Choose a reason for hiding this comment

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

Does it print inhabitantS?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, sure! Thank you :)

Comment on lines 84 to 90
inhabitant.species,
"<strong>" + inhabitant.name + "</strong>",
inhabitant.gender,
inhabitant.legs,
inhabitant.hands,
"<em>" + inhabitant.saying + "</em>",
inhabitant.friends,
Copy link
Member

Choose a reason for hiding this comment

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

There should be a way to avoid repetition of inhabitant..
How about deconstruction in function parameters definition?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've been thinking about this way past several days... I definitely want to avoid repetition, but still don't realize how to print different values with different html-styles without repetition....
Okay, I'll try to make it again

Copy link
Member

@OleksiyRudenko OleksiyRudenko Sep 7, 2022

Choose a reason for hiding this comment

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

I was referrring specifically repetition of inhabitant. fragment.
Check object deconstruction and how you could use it at function parameters definition.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've fixed it, take a look again, please.

Copy link
Member

@OleksiyRudenko OleksiyRudenko Sep 7, 2022

Choose a reason for hiding this comment

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

Now it is repetition of args. :)
Check destructuring. And here is exactly your case.
Disregard. I was looking into some other code.

@OleksiyRudenko
Copy link
Member

Check list is still valid. Go through it.
Find what became wrong.

Then make a step back and look into destructuring as commented here

@unabyband
Copy link
Contributor Author

Check list is still valid. Go through it. Find what became wrong.

Then make a step back and look into destructuring as commented here

I should avoid using "for...in" cycle here, shouldn't I?

@OleksiyRudenko
Copy link
Member

I should avoid using "for...in" cycle here, shouldn't I?

Yes, you are. And there is an explanation as to why, and the reason is valid.

Now, take a step back in your code version and make another try

@unabyband
Copy link
Contributor Author

I'm not completely sure if it's exactly what I had to do, but please review again.

Copy link
Member

@OleksiyRudenko OleksiyRudenko left a comment

Choose a reason for hiding this comment

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

@unabyband DRY code still can be customized.
Just needs a bit of creativity.

Comment on lines 91 to 92
const res = [species, name, gender, legs, hands, saying, friends];
print (res.join("; "));
Copy link
Member

Choose a reason for hiding this comment

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

Why do you need res (apart of the fact this name violates Universal requirements)?

Also bring back original formatting for name and saying.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done! Please re-review again

Copy link
Member

@OleksiyRudenko OleksiyRudenko left a comment

Choose a reason for hiding this comment

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

@unabyband great job!

P.S.
image

As you have an empty line at the end of file, this ^^ means you have non-Unix newline (most likely you have Windows CRLF).
Check your IDE and git config to ensure newline is Unix-style (LF).

Why this is important? When co-developers have different newline settings this may cause code conflicts and/or mark changes in the files where there are no actually changes beside difference in newline characters.

@OleksiyRudenko OleksiyRudenko merged commit 89fdf57 into kottans:main Sep 8, 2022
@unabyband
Copy link
Contributor Author

Thanks a lot! I found it in VSC and switch "EOL" to LF setting.

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

Successfully merging this pull request may close these issues.

2 participants