-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgeneration.js
24 lines (22 loc) · 949 Bytes
/
generation.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// Try finding your ancestors and offspring with code.
// Create a function that takes a number and "m" (for male) or "f" (for female), and returns the name of an ancestor (m/f) or descendant (m/f).
// If the number is negative, return the related ancestor.
// If positive, return the related descendant.
// You are generation 0. In the case of 0 (male or female), return "me!".
// Examples:
// generation(2, "f") ➞ "granddaughter"
// generation(-3, "m") ➞ "great grandfather"
// generation(1, "f") ➞ "daughter"
function generation(x, y) {
const main = {
"-3": { m: "great grandfather", f: "great grandmother" },
"-2": { m: "grandfather", f: "grandmother" },
"-1": { m: "father", f: "mother" },
0: { m: "me!", f: "me!" },
1: { m: "son", f: "daughter" },
2: { m: "grandson", f: "granddaughter" },
3: { m: "great grandson", f: "great granddaughter" },
};
return main[x][y];
}
console.log(generation(2, "f"));