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:
size
specifies the width and height of the diamond (both are the same).- Only odd numbers are valid for
size
:- If
size
is 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
size
at 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 (
- Important: There should be no trailing spaces after the
*
on any row. - If
size
is1
, the hollow diamond will be a single*
. - If
size
is0
or 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
size
is1
, the function should return a single*
. - If
size
is0
or negative, the function should return an empty string. - If
size
is 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
).