Skip to content

Commit

Permalink
Task a Tiny JS World (#271)
Browse files Browse the repository at this point in the history
* 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
OlexiyDobroskok authored Sep 20, 2022
1 parent 797d6f2 commit 2776e24
Showing 1 changed file with 81 additions and 0 deletions.
81 changes: 81 additions & 0 deletions submissions/OlexiyDobroskok/task_aTinyJsWorld/index.js
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("; ")));

0 comments on commit 2776e24

Please sign in to comment.