-
-
Notifications
You must be signed in to change notification settings - Fork 183
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 #36
a-tiny-JS-world #36
Conversation
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.
Good job! Now let's make it even better.
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.
Here you are only copying the initial value of the cat.saying
. You have to figure out some way to connect those values, so that if you change cat.saying
, catWoman.saying
changes as well.
hands: 2, | ||
saying: cat.saying, | ||
}; | ||
const arr = [cat, dog, man, woman, catWoman]; |
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.
Avoid using data types in the name of the variable. It is a clear indicator that your variable name isn't as obvious as it should be. Let's take this one for example. arr
of what? If you use this variable outside this code somewhere, would you be able to understand what data is inside? Let's replace it with something like inhabitants
. This gives you and understanding of what data is there and the fact that this is plural suggests that this is an array as well.
saying: cat.saying, | ||
}; | ||
const arr = [cat, dog, man, woman, catWoman]; | ||
let string = []; |
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.
Same thing, but even more confusing. A string
that is actually and array? Also, you could've print
ed every inhabitants info separately, it is not against the task, but since you are already doing this, why let
? You are not replacing the value anywhere, you are using push
. It is allowed to change the value of arrays with functions like push
even when the variable is a const
.
catWoman.prototype = cat.prototype, but I used Object.setPrototypeOf, because Object.create(prototype, descriptors) dont work properly, I dont know why. |
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.
@Eugene-CG good job!
A bit of improvement and we are done.
inhabitantsKeys.reduce((accumulator, prop) => { | ||
return (accumulator += obj[prop] + "; "); | ||
}, "") |
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.
Consider using #Array.map
(to map property names into values) and #Array.join
(to glue substrings together) here. This will make the code cleaner.
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.
@Eugene-CG well done!
Check the comment below to improve your code style a bit..
inhabitantsKeys.map((prop) => { | ||
return obj[prop]; | ||
}) |
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.
This can be reduced to inhabitantsKeys.map(prop => obj[prop])
. return
statement and surrounding {}
are redundant if return
is the only statement in arrow function body.
a-tiny-JS-world
Demo
Code base
The code is submitted in a dedicated feature branch.
Only code files are submitted.
Please, review.