In this challenge, you have to obtain a pyramidal version of a given string, transforming the string into a list containing a series of string slices that progressively increase or decrease steadily from the left to the right. Every slice containing two or more characters must have a space between every pair of characters, to permit a hypothetical vertical alignment. See the example below:
# REGULAR pyramidal version of "INNOKODAKADEMIJA"
[ "E",
"D A",
"B I T" ]
Depending on the given _type, you have to obtain a regular pyramid starting from its vertex (_type === "REG") as in the example above, or a reversed pyramid starting from its base (_type === "REV") as in the example below:
# REVERSED pyramidal version of "INNOKODAKADEMIJA"
["E D A",
"B I",
"T" ]
Every pyramid must follow the same steadily increment/decrement of its slices (or rows) by exactly one character (excluding spaces), so that not every string can be transformed in a pyramid! See the example below:
# Regular pyramidal version of "PYRAMID"
[ "P",
"Y R",
"A M I" ]
# Letter "D" can't be placed in the pyramid
Given as parameters a string and a _type, implement a function that returns:
"Error!" if the pyramidal version can't be obtained from the given string.string if the given _type is equal to "REG".string if the given _type is equal to "REV".pyramidal_string("INNOKODAKADEMIJA", "REG") ➞ ["E", "D A", "B I T"]
pyramidal_string("INNOKODAKADEMIJA", "REV") ➞ ["E D A", "B I", "T"]
pyramidal_string("PYRAMID", "REG") ➞ "Error!"
pyramidal_string("!", "REV") ➞ ["!"]
pyramidal_string("", "REG") ➞ []
string has just one character, the returned list will contain that single character. If the given string is empty, the returned list will be empty._type.