From 2776e2444815b537b032afe5f7e08372e572e1d0 Mon Sep 17 00:00:00 2001 From: Olexiy Date: Tue, 20 Sep 2022 18:53:26 +0300 Subject: [PATCH] Task a Tiny JS World (#271) * 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 --- .../task_aTinyJsWorld/index.js | 81 +++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 submissions/OlexiyDobroskok/task_aTinyJsWorld/index.js diff --git a/submissions/OlexiyDobroskok/task_aTinyJsWorld/index.js b/submissions/OlexiyDobroskok/task_aTinyJsWorld/index.js new file mode 100644 index 0000000000..24c5a27447 --- /dev/null +++ b/submissions/OlexiyDobroskok/task_aTinyJsWorld/index.js @@ -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("; ")));