Skip to content

Commit

Permalink
Tiny JS world first commit (#541)
Browse files Browse the repository at this point in the history
  • Loading branch information
daniil-bodryagin authored Sep 20, 2022
1 parent 081a32b commit 797d6f2
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions submissions/daniil-bodryagin/tiny-js-world/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { print } from './js/lib.js';

const dog = {
hands: 0,
legs: 4,
name: 'Barbos',
gender: 'male',
phrase: 'Woof-woof!',
species: 'dog',
}

const cat = {
hands: 0,
legs: 4,
name: 'Sonya',
gender: 'female',
phrase: 'Meow!',
species: 'cat'
}

const woman = {
hands: 2,
legs: 2,
name: 'Eve',
gender: 'female',
phrase: 'Hello! Glad to see you!',
species: 'human'
}

const man = {
hands: 2,
legs: 2,
name: 'Adam',
gender: 'male',
phrase: 'Hi! Today is cool!',
species: 'human'
}

const catwoman = {
hands: 2,
legs: 2,
name: 'Selina',
gender: 'female',
species: 'human'
}

catwoman.phrase = cat.phrase;

const friendsList = [
{inhabitant: dog, friends: [woman, man]},
{inhabitant: cat, friends: [woman]},
{inhabitant: woman, friends: [dog, cat, man]},
{inhabitant: man, friends: [dog, woman]},
{inhabitant: catwoman, friends: [cat, man]}
]

friendsList.forEach(({inhabitant, friends}) =>
inhabitant.friends = friends.map(({name}) => name).join(', '))

const inhabitants = [dog, cat, woman, man, catwoman];
inhabitants.map(({species, name, gender, hands, legs, phrase, friends}) =>
[species, name, gender, hands, legs, phrase, friends].join('; '))
.forEach(message => print(message));

0 comments on commit 797d6f2

Please sign in to comment.