I am new to programming, I am familiar with JavaScript, and I just learned the concept of recursion. Now I have been given a problem to create a function (e.g. const f = function(n) { }), and if we call the function c f(5), we should see:
*
***
*****
*******
*********
The number of vertical stars should be determined by the input. I have to use no for / while / do -while; recursion only in a loop.
I came up with this code to combine 5 stars
const f = function(n) {
if (n === 0) {
return "";
}
return "*" + f(n - 1);
};
console.log(f(5));
Although, I donβt see how to make a triangle, what can I do?
source
share