Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function christmasTree(height) {
- let max = 0
- let m = 0
- for (let i = 0; m < height; i++) {
- if ((i % 2) == 0) { continue }
- max = i
- m++
- }
- const mmm = max
- let answer = '';
- let stars = 1
- for (let z = 0; z < height; z++) {
- //console.log(row(max))
- answer += row(max);
- function row(max) {
- if (max == 0) {
- return '\n'
- }
- if ((((mmm - stars) / 2) + stars) < max) {
- return row(max - 1) + ' '
- }
- if (((mmm - stars) / 2) < max) {
- return row(max - 1) + '*'
- }
- if (0 < max) {
- return row(max - 1) + ' '
- }
- }
- stars++
- stars++
- }
- return answer.substring(1); // краще не так робити,))
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement