constdrawRow=(qty,replaceWith)=>{letstr="";for(leti=0;i<qty;i++){str+=replaceWith;}returnstr;};constprintDiamond=(n)=>{if(n%2===0||n<0){return"The number should be odd and positive";}letrow="";letstars=0;for(leti=0;i<n;i++){if(i>parseInt(n/2)){stars-=2;}else{stars=i*2+1;}constspaces=(n-stars)/2;row+=drawRow(spaces,"");row+=drawRow(stars,"*");row+=drawRow(spaces,"");if(i!==n-1){row+="\n";}}returnrow;};console.log(printDiamond(11));
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
JS