Your task is to extend the functionality of the generatePattern(style, dimensions) function to support a new pattern type: triangle.
For this assignment, the style parameter will be "triangle", and the dimensions parameter will be an array containing a single number [size] where:
sizespecifies the number of rows in the triangle.- The width of each row corresponds to its row number (1-based). For example, the 1st row has 1
*, the 2nd row has 2*, and so on.
- The triangle starts with 1
*in the first row and increases in width by 1*for each subsequent row. - If
sizeis0, the triangle is considered empty, and the function should return an empty string.
generatePattern("triangle", [3]);
// Output:
*
**
***
generatePattern("triangle", [5]);
// Output:
*
**
***
****
*****
generatePattern("triangle", [1]);
// Output:
*
generatePattern("triangle", [0]);
// Output: (empty string)- The triangle pattern should properly handle edge cases:
- If
sizeis1, the function should return a single*. - If
sizeis0, the function should return an empty string. - For larger values of
size, ensure the correct number of rows and*characters per row.
- If
- Each line of the output should be separated by a newline character (
\n). - Ensure that the function works for both small and large values of
size.