-
-
Notifications
You must be signed in to change notification settings - Fork 184
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Task a Tiny JS World * delete for...in loop and add forEach * Added array#map and array#filter method for allProperties array * Made the code a little cleaner
- Loading branch information
1 parent
797d6f2
commit 2776e24
Showing
1 changed file
with
81 additions
and
0 deletions.
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,81 @@ | ||
/* 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/OlexiyDobroskok/a-tiny-JS-world | ||
Web app: https://olexiydobroskok.github.io/a-tiny-JS-world/ | ||
*/ | ||
|
||
// ======== OBJECTS DEFINITIONS ======== | ||
|
||
const man = { | ||
species: "human", | ||
name: "José", | ||
gender: "male", | ||
legs: 2, | ||
hands: 2, | ||
saying: "Hola, amigo!", | ||
friends: ["Nerea", "Lalo"], | ||
}; | ||
|
||
const woman = { | ||
species: "human", | ||
name: "Martina", | ||
gender: "female", | ||
legs: 2, | ||
hands: 2, | ||
saying: "Buenos días!", | ||
friends: ["Pako"], | ||
}; | ||
|
||
const cat = { | ||
species: "cat", | ||
name: "Lalo", | ||
gender: "female", | ||
legs: 4, | ||
hands: 0, | ||
saying: "¡miau miau!", | ||
friends: ["José", "Nerea"], | ||
}; | ||
|
||
const dog = { | ||
species: "dog", | ||
name: "Pako", | ||
gender: "male", | ||
legs: 4, | ||
hands: 0, | ||
saying: "¡guau guau!", | ||
friends: ["Martina"], | ||
}; | ||
|
||
const catwoman = { | ||
species: "human", | ||
name: "Nerea", | ||
gender: "female", | ||
legs: 2, | ||
hands: 2, | ||
saying: cat.saying + " muchachos!", | ||
friends: ["José", "Lalo"], | ||
}; | ||
|
||
// ======== OUTPUT ======== | ||
|
||
const aTinyWorld = [man, woman, cat, dog, catwoman]; | ||
const properties = [ | ||
"species", | ||
"name", | ||
"gender", | ||
"legs", | ||
"hands", | ||
"saying", | ||
"friends", | ||
]; | ||
|
||
const residentsProperties = aTinyWorld.map((resident) => { | ||
return properties | ||
.map((prop) => { | ||
return resident[prop]; | ||
}) | ||
.filter((prop) => prop !== 0 && prop !== ""); | ||
}); | ||
|
||
residentsProperties.forEach((prop) => print(prop.join("; "))); |