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 task #414

Merged
merged 4 commits into from
Sep 23, 2022
Merged

A tiny JS world task #414

merged 4 commits into from
Sep 23, 2022

Conversation

deveLabR
Copy link
Contributor

@deveLabR deveLabR commented Sep 3, 2022

Building a Tiny JS World

Demo |
Code base

The code is submitted in a dedicated feature branch.

Only code files are submitted.

Please, review.

@github-actions
Copy link

github-actions bot commented Sep 3, 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 😺

@deveLabR
Copy link
Contributor Author

deveLabR commented Sep 4, 2022

Self-check 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.

@deveLabR well done!
Let's polish it.

Comment on lines 64 to 68
const arr = [];
attr.forEach((key) => {
obj[key] && arr.push(obj[key]);
});
return arr.join('; ') + '.';
Copy link
Member

Choose a reason for hiding this comment

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

A classic use case for Array#map

@yaripey yaripey self-assigned this Sep 18, 2022
Copy link

@yaripey yaripey left a comment

Choose a reason for hiding this comment

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

Hey, good job, you're almost there! Let's improve some things. Check the comments below.

];

function tellMeAboutYou(obj) {
const arr = [];
Copy link

Choose a reason for hiding this comment

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

Let's make a better name for this variable. You almost never want to use the data type in the name of the variable, it is an indicator that the name is not descriptive enough. Maybe something like personInfoItems?


const persons = [dog, cat, man, woman, catWoman];

const attr = [
Copy link

Choose a reason for hiding this comment

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

Let's use attributes here. Plural implies that this is an array and not just one attribute and helps readability.


function tellMeAboutYou(obj) {
const arr = [];
attr.map((key) => {
Copy link

Choose a reason for hiding this comment

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

Array method map() creates a new array of elements that are returned from each callback function that is called for each element of the initial array. You don't need to create a separate empty array before and push it there. You can just do

const result = someArray.map(...)

Or even faster, since you're not doing anything more here:

return someArray.map(...).join(...)

gender: 'female',
legs: 2,
hands: 2,
saying: cat.saying,
Copy link

Choose a reason for hiding this comment

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

The task implies that the catwoman would ALWAYS say what the cat says. It means that if we change the cat's saying later in the code, Catwoman should say the new line, not the initial, as yours does. You need to find a way to connect catwoman's saying with the cat's object, not just assign an initial cat.saying value.

@deveLabR deveLabR requested review from yaripey and removed request for OleksiyRudenko September 19, 2022 13:10
return attributes.map((key) => obj[key]).join('; ') + '.';
}

persons.map((item) => print(personInfoItems(item)));
Copy link

Choose a reason for hiding this comment

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

If you're .maping on persons, then elements inside are persons, right? item isn't descriptive enough.

'friends',
];

function personInfoItems(obj) {
Copy link

Choose a reason for hiding this comment

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

What obj, exactly? I believe this should be person.

catWoman.gender = 'female';
catWoman.legs = 2;
catWoman.hands = 2;
catWoman.friends = cat.name;
Copy link

Choose a reason for hiding this comment

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

You didn't see a problem in this task, because it's pretty simple here, but note that your .friends for all other objects is an array. And your catWoman.friends is a string for some reason. The only thing that you're doing here is printing stuff out, so it didn't invoke an error, but imagine that you did something like .friends.map to print every friend separately, the code wouldn't work here, since string doesn't have .map() method.

If you wish to specify that catWoman has only one friend, you should still keep the data type and just make it like this:

catWoman.friends = [cat.name];

@deveLabR deveLabR requested a review from yaripey September 22, 2022 19:55
Copy link

@yaripey yaripey left a comment

Choose a reason for hiding this comment

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

LGTM Let's wait for @OleksiyRudenko's verdict.

@deveLabR
Copy link
Contributor Author

I need to press Re-review?

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.

@deveLabR great job!

@OleksiyRudenko OleksiyRudenko merged commit 9f9982a into kottans:main Sep 23, 2022
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.

4 participants