Skip to content

Commit da61155

Browse files
author
juanantonioledesma
committed
Add "ASCII Fun #2: Funny Dots" kata
1 parent 67a5d3a commit da61155

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

6-kyu/ascii-fun-2-funny-dots.md

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<h1>ASCII Fun #2: Funny Dots <sup><sup>6 Kyu</sup></sup></h1>
2+
3+
<sup>
4+
<a href="https://www.codewars.com/kata/59098c39d8d24d12b6000020">
5+
<strong>LINK TO THE KATA</strong>
6+
</a> - <code>ASCII ART</code>
7+
</sup>
8+
9+
## Description
10+
11+
You will get two integers `n` (width) and `m` (height) and your task is to draw the following pattern. Each line is seperated with a newline (`\n`)
12+
13+
Both integers are equal or greater than 1; no need to check for invalid parameters.
14+
15+
**Examples**
16+
17+
```
18+
+---+---+---+
19+
+---+ | o | o | o |
20+
dot(1, 1) => | o | dot(3, 2) => +---+---+---+
21+
+---+ | o | o | o |
22+
+---+---+---+
23+
```
24+
25+
## Solution
26+
27+
```javascript
28+
const SIMPLE_ROW_CHARACTERS = '+---'
29+
const END_SIMPLE_ROW_CHARACTERS = '+'
30+
const DOT_ROW_CHARACTERS = '| o '
31+
const END_DOT_ROW_CHARACTERS = '|'
32+
33+
const dot = (width, height) => {
34+
let result = []
35+
36+
const simpleRow = `${SIMPLE_ROW_CHARACTERS.repeat(
37+
width,
38+
)}${END_SIMPLE_ROW_CHARACTERS}`
39+
40+
const donutRow = `${DOT_ROW_CHARACTERS.repeat(
41+
width,
42+
)}${END_DOT_ROW_CHARACTERS}`
43+
44+
for (let i = 0; i < height; i++) {
45+
result.push(simpleRow)
46+
result.push(donutRow)
47+
}
48+
result.push(simpleRow)
49+
50+
return result.join('\n')
51+
}
52+
```

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ JavaScript katas on Codewars are programming challenges that help you improve yo
2828
- **[Are they the "same"?](./6-kyu/are-they-the-same.md)**
2929
- **[Array.diff](./6-kyu/array-diff.md)**
3030
- **[ASCII Fun #1: X-Shape](./6-kyu/ascii-fun-1-x-shape.md)**
31+
- **[ASCII Fun #2: Funny Dots](./6-kyu/ascii-fun-2-funny-dots.md)**
3132
- **[Bit Counting](./6-kyu/bit-counting.md)**
3233
- **[Break camelCase](./6-kyu/break-camel-case.md)**
3334
- **[Build Tower!](./6-kyu/build-tower.md)**

0 commit comments

Comments
 (0)