In this challenge, you have to obtain a pyramidal version of a given string, transforming the string into an array 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".pyramidalString("INNOKODAKADEMIJA", "REG") ➞ ["E", "D A", "B I T"]
pyramidalString("INNOKODAKADEMIJA", "REV") ➞ ["E D A", "B I", "T"]
pyramidalString("PYRAMID", "REG") ➞ "Error!"
pyramidalString("!", "REV") ➞ ["!"]
pyramidalString("", "REG") ➞ []
string has just one character, the returned array will contain that single character. If the given string is empty, the returned array will be empty.type.