A couple is putting up the Christmas tree. The boy loves Christmas decorations and wants it to be perfectly balanced. He has three types of decorations:
The Christmas tree is a triangle that must be generated. They already have the base mounted, which would be the first row, and from there they have to place the decorations upwards following a formula.
Place on top : P R B P If below is : P P B P R P B R
The combinations are also reversed. For example, if below is
B P, above is
R. But it will also be
R if below is
P B. Also if below you have repeated the letter, above you use the same letter. For example: if below is
B B, above is
With these rules, we could see the tree that we would generate with the base
B P R P:
R P B R B B B P R P
Write a program that receives the string
B P R P and returns an array with the representation of the tree.
decorateTree('B P R P') // [ // 'R', // 'P B', // 'R B B', // 'B P R P' // ] decorateTree('B B') // ['B', 'B B']
Keep in mind that: