-
-
Notifications
You must be signed in to change notification settings - Fork 184
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
add tiny-js-world homework #193
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* Refer to https://github.com/OleksiyRudenko/a-tiny-JS-world for the task details | ||
Complete the below for code reviewers' convenience: | ||
|
||
Code repository: https://github.com/bmukha/a-tiny-JS-world | ||
Web app: https://bmukha.github.io/a-tiny-JS-world/ | ||
*/ | ||
|
||
const dog = { | ||
species: 'dog', | ||
name: 'Beethoven', | ||
gender: 'male', | ||
legs: 4, | ||
hands: 0, | ||
saying: 'woof', | ||
friends: ['Clyde'], | ||
}; | ||
|
||
const cat = { | ||
species: 'cat', | ||
name: 'Grizabella', | ||
gender: 'female', | ||
legs: 4, | ||
hands: 0, | ||
saying: 'meow', | ||
friends: ['Bonnie'], | ||
}; | ||
|
||
const man = { | ||
species: 'human', | ||
name: 'Clyde', | ||
gender: 'male', | ||
legs: 2, | ||
hands: 2, | ||
saying: 'Get rich or die trying!', | ||
friends: ['Bonnie', 'Beethoven'], | ||
}; | ||
|
||
const woman = { | ||
species: 'human', | ||
name: 'Bonnie', | ||
gender: 'female', | ||
legs: 2, | ||
hands: 2, | ||
saying: 'I have the right to not answer a questions!', | ||
friends: ['Clyde', 'Grizabella'], | ||
}; | ||
|
||
const catwoman = { | ||
species: 'human', | ||
name: 'Selina', | ||
gender: 'female', | ||
legs: 2, | ||
hands: 2, | ||
saying: cat.saying, | ||
friends: [], | ||
}; | ||
|
||
const characters = [dog, cat, man, woman, catwoman]; | ||
|
||
const props = [ | ||
'species', | ||
'name', | ||
'gender', | ||
'legs', | ||
'hands', | ||
'saying', | ||
'friends', | ||
]; | ||
|
||
characters.forEach((character) => { | ||
let representation = ''; | ||
for (let i = 0; i < props.length; i++) { | ||
if (props[i] === 'hands' && character[props[i]] === 0) { | ||
continue; | ||
} else if (i < props.length - 1) { | ||
representation += `${character[props[i]]}; `; | ||
} else { | ||
representation += `${character[props[i]].join(', ')}`; | ||
} | ||
} | ||
print(representation); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 improve readability here.
Use
Array#filter
to skip properties where their names and/or values to do not meet criteria.Use
Array#map
method to convert property names into property values.Glue them all with
Array#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.
Tnx for the suggestions. I just refactored the code according to them. Please, re-review.