-
Notifications
You must be signed in to change notification settings - Fork 0
/
kata.js
29 lines (22 loc) · 829 Bytes
/
kata.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
function pyramid(n){
//your code here
let result = '';
let counter = 0;
for (let i = 1; i <= n; i++) {
result += `${' '.repeat(n-i)}${'/'}${i<n ? ' '.repeat(counter) : '_'.repeat(counter)}${'\\'}\n`
result.trimEnd();
counter+=2
}
return n != 0 ? result : '\n';
}
console.log(pyramid(0));
console.log(pyramid(1));
// "/\\\n");
console.log(pyramid(2));
// " /\\\n/__\\\n");
console.log(pyramid(4));
// " /\\\n / \\\n / \\\n/______\\\n");
console.log(pyramid(6));
// " /\\\n / \\\n / \\\n / \\\n / \\\n/__________\\\n");
console.log(pyramid(10));
//" /\\\n / \\\n / \\\n / \\\n / \\\n / \\\n / \\\n / \\\n / \\\n/__________________\\\n");