MCPcopy Create free account
hub / github.com/asweigart/PythonStdioGames / displayFilledDiamond

Function displayFilledDiamond

javascript_games/diamonds.js:49–65  ·  view source on GitHub ↗
(size)

Source from the content-addressed store, hash-verified

47}
48
49function displayFilledDiamond(size) {
50 // Display the top half of the diamond:
51 for (let i = 0; i < size; i++) {
52 process.stdout.write(' '.repeat(size - i - 1)); // Left side space.
53 process.stdout.write('/'.repeat(i + 1)); // Left half of diamond.
54 process.stdout.write('\\'.repeat(i + 1)); // Right half of diamond.
55 console.log();
56 }
57
58 // Display the bottom half of the diamond:
59 for (let i = 0; i < size; i++) {
60 process.stdout.write(' '.repeat(i)); // Left side space.
61 process.stdout.write('\\'.repeat(size - i)); // Left side of diamond.
62 process.stdout.write('/'.repeat(size - i)); // Right side of diamond.
63 console.log();
64 }
65}
66
67main();

Callers 1

mainFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected