I'm guessing you're asking how you would end up rendering it inside of React. There's several ways you could go about it, but here's a quick example of how I would go about it.
const Stars = () => {
const handleStars = (lim) => {
let arr = new Array(lim);
for(let i=0; i<=lim; i++){
let str = '';
for(let j=-1; j<=i; j++){
str += '*';
}
arr[i] = str;
}
return arr;
}
return (
<div>Here be stars:
{
handleStars(5).map( (e, i) => {
return <p key={i}>{e}</p>
})
}
</div>
)
}
export default Stars;
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…