Your decision is slightly shorter:
- learn in advance the number of iterations
i = (n - 1) * 2 + 1 and in each iteration of the cycle we print the asterisk len -fold using the repeat line method - at the end of the iteration, we change the length up or down using the vector
len += vector - we expand the vector from the direction of decrease towards the increase as soon as we reach the minimum (unit length of the string with asterisks)
== 1 && (vector = 1)
(function(n){ for ( let i = (n - 1) * 2 + 1, len = n, vector = -1; i--; ) { console.log('*'.repeat(len)); (len += vector) == 1 && (vector = 1); } })(4);
You can make it even easier if you find the formula for the dependence of the number of stars on the line number. To do this, turn your head 90 degrees to the right looking at your question. You will get something like this:

OX and OY axes are striking. Let us draw two straight lines along the tops of the stars: the first of the point {0, 5} in {4, 1} , and the second of {4, 1} in {8, 5} . Now we find the equation of a line passing through two given mismatched points for each of them.
(y1 - y2) * x + (x2 - x1) * y + (x1 * y2 - x2 * y1) = 0
For the first, we get y = 5 - x , for the second, y = x - 3 , where x is the iteration number in your cycle, and y is the number of stars for the repeat function. It remains to add a check in the cycle at the intersection of the middle of the graph. Before him use the first formula, after - the second.
n7--.. - entithat