-
-
Notifications
You must be signed in to change notification settings - Fork 184
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
A tiny JS world task #414
Conversation
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 listRelates to Object-Oriented JavaScript task. Check-list - definition of done
Universal recommendations:
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, |
Self-check done. |
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.
@deveLabR well done!
Let's polish it.
const arr = []; | ||
attr.forEach((key) => { | ||
obj[key] && arr.push(obj[key]); | ||
}); | ||
return arr.join('; ') + '.'; |
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.
A classic use case for Array#map
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.
Hey, good job, you're almost there! Let's improve some things. Check the comments below.
]; | ||
|
||
function tellMeAboutYou(obj) { | ||
const arr = []; |
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.
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 = [ |
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.
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) => { |
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.
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, |
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 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.
return attributes.map((key) => obj[key]).join('; ') + '.'; | ||
} | ||
|
||
persons.map((item) => print(personInfoItems(item))); |
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.
If you're .map
ing on persons
, then elements inside are person
s, right? item
isn't descriptive enough.
'friends', | ||
]; | ||
|
||
function personInfoItems(obj) { |
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.
What obj
, exactly? I believe this should be person
.
catWoman.gender = 'female'; | ||
catWoman.legs = 2; | ||
catWoman.hands = 2; | ||
catWoman.friends = cat.name; |
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.
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];
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.
LGTM Let's wait for @OleksiyRudenko's verdict.
I need to press Re-review? |
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.
@deveLabR great job!
Building a Tiny JS World
Demo |
Code base
The code is submitted in a dedicated feature branch.
Only code files are submitted.
Please, review.