Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function diamond(number) {
- let num = parseInt(number);
- for (let i = 0; i < num / 2; i++) {
- if (i === 0) {
- console.log(`${'-'.repeat(((num - 1) / 2) - i)}${num % 2 === 0 ? '**' : '*'}${'-'.repeat((num - 1) / 2 - i)}`);
- } else {
- console.log(`${'-'.repeat(((num - 1) / 2) - i)}*${'-'.repeat(i * 2 - num % 2)}*${'-'.repeat((num - 1) / 2 - i)}`);
- }
- }
- for (let i = (num - 2 + (num % 2)) / 2 - 1; i >= 0; i--) {
- if (i === 0) {
- console.log(`${'-'.repeat(((num - 1) / 2) - i)}${num % 2 === 0 ? '**' : '*'}${'-'.repeat((num - 1) / 2 - i)}`);
- } else {
- console.log(`${'-'.repeat(((num - 1) / 2) - i)}*${'-'.repeat(i * 2 - num % 2)}*${'-'.repeat((num - 1) / 2 - i)}`);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement