-
-
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
New index.js for tiny js task #258
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. Sincerely yours, |
Опрацьовано |
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.
@Levi123 please go through the check list once again. I figured at least two requirements not met.
Feel free asking questions if anything is not clear.
submissions/Levi123/tiny-JS/index.js
Outdated
function printObject(object){ | ||
const prop = []; | ||
for (element in object){ | ||
prop.push(object[element]); | ||
} | ||
let newStr = prop.join('; '); | ||
print(newStr); | ||
} |
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.
- 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.
Object
methods likekeys
,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 tofor...of
andfor...in
when applied to objects.
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.
- 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.
Object
methods likekeys
,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 tofor...of
andfor...in
when applied to objects.
I don't understand second point of your massage, i can't use (for...in) at all? and 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.
Q: I can't use (for...in) at all? and why?
A: As per explanation above "...when a particular order is required as these do not guarantee any particular order of keys/values."
Only arrays guarantee order of elements.
As a peer developer, knowing that in objects order of keys is not important I can define new objects with properties in different order. It would be great if this didn't affect the code.
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.
Q: I can't use (for...in) at all? and why?
A: As per explanation above "...when a particular order is required as these do not guarantee any particular order of keys/values."
Only arrays guarantee order of elements.
As a peer developer, knowing that in objects order of keys is not important I can define new objects with properties in different order. It would be great if this didn't affect the code.
I try to change my errors.
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.
@Levi123 good improvement.
Still further improvements are needed.
submissions/Levi123/tiny-JS/index.js
Outdated
const propToPrint = []; | ||
prop.forEach((propOfObj) => { | ||
propToPrint.push(personToPrint[propOfObj]); | ||
}) | ||
let newStr = propToPrint.join('; '); | ||
print(newStr); |
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.
Think of converting property names into object's property values, then joining with '; '
.
Make the method return the result. Currently it does two jobs: (1) convert data, (b) produce output, which doesn't really follow Separatoin of Concerns principles.
Use Array.map
method to convert data.
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.
@OleksiyRudenko did I understand correctly, I need to split this function into several?
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 should use print
inside this method. You can call print
in a fragment of code where you want the output to happen in. And this function will do a single job - transformation of data. You will end up with a one-liner here.
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.
@Levi123 while looking through your updated code version I started wondering why is it so.
I am sorry, I apparently missed one very important word here. The comment above should read
You should not use
My apologies. We will fix this.
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.
@Levi123переглядаючи вашу оновлену версію коду, я почав дивуватися, чому це так.
Вибачте, я, мабуть, пропустив тут одне дуже важливе слово. Коментар вище має прочитати
Ви не повинні використовувати всередині
Мої вибачення. Ми це виправимо.
i don't understand you
submissions/Levi123/tiny-JS/index.js
Outdated
printObjectNew(catWoman); | ||
printObjectNew(male); | ||
printObjectNew(female); | ||
printObjectNew(cat); | ||
printObjectNew(dog); |
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.
From the checklist above in the thread:
- 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 employingArray.forEach
as the least`${obj.legs}; ${obj.name}; etc...`
(yes, strings are also code) must be refactored employing appropriateArray
methods
Requirements are always requirements. Double-check yourself against requirements until the principles helping to design a clean code become a habit.
@OleksiyRudenko i try to fix my errors |
submissions/Levi123/tiny-JS/index.js
Outdated
function arrayToString(propToPrint){ | ||
let newStr = propToPrint.join('; '); | ||
console.log(propToPrint); | ||
print(newStr); |
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 function promises to convert an array to a string but it also prints.
Also remove calls to console
before submitting code.
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.
done
submissions/Levi123/tiny-JS/index.js
Outdated
const propToPrint = []; | ||
prop.forEach((propOfObj) => { | ||
propToPrint.push(personToPrint[propOfObj]); | ||
}) |
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 perfect use case for Array#map
method.
Also prop
is a global variable. Do not use global variables where there is no need, esp. if it is used in a specific function and only there.
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.
@OleksiyRudenko done
submissions/Levi123/tiny-JS/index.js
Outdated
// printObjectNew(male); | ||
// printObjectNew(female); | ||
// printObjectNew(cat); | ||
// printObjectNew(dog); |
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.
Make your code editor to ensure you always have an empty line at the end of file. There must be a setting. Check this
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.
Thank you! Done
submissions/Levi123/tiny-JS/index.js
Outdated
const propToPrint = []; | ||
prop.forEach((propOfObj) => { | ||
propToPrint.push(personToPrint[propOfObj]); | ||
}) | ||
let newStr = propToPrint.join('; '); | ||
print(newStr); |
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.
@Levi123 while looking through your updated code version I started wondering why is it so.
I am sorry, I apparently missed one very important word here. The comment above should read
You should not use
My apologies. We will fix this.
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.
@Levi123 you did a great job, given I missed one improtant word in my feedback on previous iteration of code review.
Let's make a step back.
Read the comments below and let's transform the list of inhabitants without defining any additional functions at all.
Feel free asking questions and suggesting a relevant fragment of code.
Sorry, but i don't understand what i must do. |
Remove functions used to transform data and write a fragment of code that prints presentation strings based on |
check my code pls |
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.
@Levi123 quite a decent job!
Consider mastering Array
methods chaining. This will reduce number of lines of code to write and will add to code readability.
a Tiny JS world
Demo |
Code base
The code is submitted in a dedicated feature branch.
Only code files are submitted.
Please, review.