Your task is to extend the functionality of the generatePattern(style, dimensions) function to support a new pattern type: hollow-diamond.
For this assignment, the style parameter will be "hollow-diamond", and the dimensions parameter will be an array containing a single number [size] where:
sizespecifies the width and height of the diamond (both are the same).- Only odd numbers are valid for
size:- If
sizeis an even number, your function should generate a hollow diamond for the closest odd number below it. - For example, if
size = 4, the function should generate a hollow diamond of size3.
- If
- The hollow diamond is symmetrical, with a maximum width of
sizeat its middle row. - Each row consists of a single
*at the beginning and end of the row (except the middle row, which is filled with*). - Spaces (
) are used to maintain the diamond's shape. - Important: There should be no trailing spaces after the
*on any row. - If
sizeis1, the hollow diamond will be a single*. - If
sizeis0or less, the hollow diamond is considered empty, and the function should return an empty string.
generatePattern("hollow-diamond", [3]);
// Output:
*
* *
*
generatePattern("hollow-diamond", [7]);
// Output:
*
* *
* *
* *
* *
* *
*
generatePattern("hollow-diamond", [4]); // Closest odd size is 3
// Output:
*
* *
*
generatePattern("hollow-diamond", [1]);
// Output:
*
generatePattern("hollow-diamond", [0]);
// Output: (empty string)- No trailing spaces: Each row must end precisely after the last
*. Do not leave unnecessary spaces at the end of any row. - The hollow diamond pattern should properly handle edge cases:
- If
sizeis1, the function should return a single*. - If
sizeis0or negative, the function should return an empty string. - If
sizeis even, generate a hollow diamond using the closest odd number below it.
- If
- Each line of the output should be separated by a newline character (
\n).