MeGaDeTH_91

MM Print

May 5th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. function PrintMM(num){
  2. const spaceSymbol = '-';
  3. const wordSymbol = '*';
  4. let half = Math.floor(num / 2);
  5. let border = Math.ceil(num / 2);
  6. let result = '';
  7.  
  8. for (let i = 0; i < border; i++) {
  9. result += spaceSymbol.repeat(Math.max(num - i, 0));
  10. result += wordSymbol.repeat(Math.max(i * 2 + num, 0));
  11. result += spaceSymbol.repeat(Math.max(num - i * 2, 0));
  12. result += wordSymbol.repeat(Math.max(i * 2 + num, 0 ));
  13. result += spaceSymbol.repeat(Math.max(num * 2 - i * 2, 0));
  14. result += wordSymbol.repeat(Math.max(i * 2 + num, 0));
  15. result += spaceSymbol.repeat(Math.max(num - i * 2, 0));
  16. result += wordSymbol.repeat(Math.max(i * 2 + num, 0 ));
  17. result += spaceSymbol.repeat(Math.max(num - i, 0));
  18. result += '\n';
  19. }
  20.  
  21. for (let i = 0; i < border; i++) {
  22. result += spaceSymbol.repeat(Math.max(half - i, 0));
  23. result += wordSymbol.repeat(Math.max(num, 0));
  24. result += spaceSymbol.repeat(i * 2 + 1);
  25. result += wordSymbol.repeat(Math.max(num * 2 - 1 - 2 * i, 0));
  26. result += spaceSymbol.repeat(i * 2 + 1);
  27. result += wordSymbol.repeat(Math.max(num, 0));
  28. result += spaceSymbol.repeat(Math.max(num - 1 - i * 2, 0));
  29. result += wordSymbol.repeat(Math.max(num, 0));
  30. result += spaceSymbol.repeat(i * 2 + 1);
  31. result += wordSymbol.repeat(Math.max(num * 2 - 1 - 2 * i, 0));
  32. result += spaceSymbol.repeat(i * 2 + 1);
  33. result += wordSymbol.repeat(Math.max(num, 0));
  34. result += spaceSymbol.repeat(Math.max(half - i, 0));
  35. result += '\n';
  36. }
  37. console.log(result);
  38. }
  39.  
  40. PrintMM(7);
Advertisement
Add Comment
Please, Sign In to add comment