Advertisement
Timkor

codewarsTree

Jan 20th, 2021
743
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function christmasTree(height) {
  2.     let max = 0
  3.     let m = 0
  4.     for (let i = 0; m < height; i++) {
  5.         if ((i % 2) == 0) { continue }
  6.         max = i
  7.         m++
  8.     }
  9.     const mmm = max
  10.     let answer = '';
  11.     let stars = 1
  12.     for (let z = 0; z < height; z++) {
  13.         //console.log(row(max))
  14.         answer += row(max);
  15.         function row(max) {
  16.             if (max == 0) {
  17.                 return '\n'
  18.             }
  19.             if ((((mmm - stars) / 2) + stars) < max) {
  20.                 return row(max - 1) + ' '
  21.             }
  22.             if (((mmm - stars) / 2) < max) {
  23.                 return row(max - 1) + '*'
  24.             }
  25.             if (0 < max) {
  26.                 return row(max - 1) + ' '
  27.             }
  28.  
  29.         }
  30.         stars++
  31.         stars++
  32.  
  33.     }
  34.   return answer.substring(1); // краще не так робити,))
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement