-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathx-cape-printSquares.js
86 lines (66 loc) · 1.38 KB
/
x-cape-printSquares.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// Note: I'm evaluating your answer on the simplicity of your code. The goal is for it to be readable; someone new should be able to walk into this room afterward and instantly understand what your function is doing.
// Draw Square
// Draw a square inside of a square
// draw_square(outer, inner)
// Given:
// Outer = size of outer square
// Inner = size of inner square
// Outer > Inner >= 1
// Output:
// String representation of inner and outer squares
// Ex:
// draw_square(5, 3)
// -----
// -+++-
// -+++-
// -+++-
// -----
// draw_square(6, 3)
// ------
// -+++--
// -+++--
// -+++--
// ------
// ------
// draw_square(5, 1)
// -----
// -----
// --+--
// -----
// -----
// draw_square(2, 1)
// +-
// --
// draw_square(4, 3)
// xxx-
// xxx-
// xxx-
// ----
// xxx-
// +-
// 4 - 2 = 2 => ++ --
// -++- // -
// -+-
// 6 - 3 = 3 / 2 = 1 || 2
// -+++--
//
// p: num, num
// r: string
const draw_square = (outter, inner) => {
const minus = "-";
const plus = "+";
let outterStr = "-".repeat(outter);
let innerStr = "";
let diff = outter - inner;
let firstOfOutter = Math.floor(diff / 2);
let basicLine =
minus.repeat(firstOfOutter) +
plus.repeat(inner) +
minus.repeat(diff - firstOfOutter);
let basicInner = basicLine(inner);
// for (let i = 1; i <= outter; i++) {
// for (let j = 1; j <= inner; j++) {
// }
// }
};
// console.log(draw_square(5,3))