If you are not punished for every line of code you write, this code is fine: concise and very clear.
If you get punished, just use:
for (var i = 0; i < x; i++) arr.push(x);
in one line :-)
In addition, the function in the following areas will be the best choice:
arr = appendXCopiesOfX (arr, x);
but I donβt think that you are really typing something there, because, as already mentioned, there should be very few problems understanding such a short cycle.
All in all, it is probably a waste of time and effort trying to improve what you have.
source share