You are given a data structure that represents Pokemon evolutions
The data structure looks like this:
{
name: "A", // can evolve to B and E
evolutions: [{
name: "B", // can evolve to C
evolutions: [{
name: "C", // can evolve to D
evolutions: ["D"] // cannot further evolve
}]
},
"E" // cannot further evolve
]
}
- Pokemon that do not evolve further are represented as strings rather than objects.
- While the provided examples only go to a depth of 3, you should provide a solution that works for any tree depth (ignoring memory constraints)
- Your task: write a function that produces a string showing the hierarchy of how Pokemon evolve, with each evolution level indented by one space:
A
B
C
D
E
Full input data:
[
{
name: "Bulbasaur",
evolutions: [
{
name: "Ivysaur",
evolutions: ["Venusaur"]
}
]
},
{
name: "Charmander",
evolutions: [
{
name: "Charmeleon",
evolutions: ["Charizard"]
}
]
},
{
name: "Squirtle",
evolutions: [
{
name: "Wartortle",
evolutions: ["Blastoise"]
}
]
},
{
name: "Pichu",
evolutions: [
{
name: "Pikachu",
evolutions: ["Raichu"]
}
]
},
{
name: "Nidoran",
evolutions: [
{
name: "Nidorino",
evolutions: ["Nidoking"]
},
{
name: "Nidorina",
evolutions: ["Nidoqueen"]
}
]
},
{
name: "Oddish",
evolutions: [
{
name: "Gloom",
evolutions: ["Vileplume", "Bellossom"]
}
]
},
{
name: "Slowpoke",
evolutions: ["Slowbro", "Slowking"]
},
{
name: "Tyrogue",
evolutions: ["Hitmonlee", "Hitmonchan", "Hitmontop"]
},
{
name: "Evee",
evolutions: [
"Vaporeon",
"Jolteon",
"Flareon",
"Espeon",
"Umbreon",
"Leafeon",
"Glaceon",
"Sylveon"
]
},
"Zapdos",
]
full output:
Bulbasaur
Ivysaur
Venusaur
Charmander
Charmeleon
Charizard
Squirtle
Wartortle
Blastoise
Pichu
Pikachu
Raichu
Nidoran
Nidorino
Nidoking
Nidorina
Nidoqueen
Oddish
Gloom
Vileplume
Bellossom
Slowpoke
Slowbro
Slowking
Tyrogue
Hitmonlee
Hitmonchan
Hitmontop
Evee
Vaporeon
Jolteon
Flareon
Espeon
Umbreon
Leafeon
Glaceon
Sylveon
Zapdos