-
Notifications
You must be signed in to change notification settings - Fork 0
/
pattern.js
66 lines (49 loc) · 1.15 KB
/
pattern.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
class Solution {
reverseWord(str){
//Your code here
str = str.split("")
for(let itr= 0 ; itr < str.length/2 ; itr++) {
let ch = str[itr];
str[itr] = str[(str.length - 1 - itr)];
str[(str.length - 1 - itr)] = ch;
}
str = str.join("");
return str;
}
}
let testCases = [
"Geeks",
"for",
"g"
];
let obj = new Solution();
for (let caseNum = 0; caseNum < testCases.length; caseNum++) {
console.log("test case " + caseNum + " "+ obj.reverseWord(testCases[caseNum]))
}
/**
*
* * *
* * * * *
* * * * * * *
* * * * * * * * *
row // 0 , 1 , 2 , 3, 4
number of rows // 5
series spaces // 4 , 3 , 2 , 1, 0
series star // 1, 2 , 3, 4, 5
n = 5
// case 1
rowItr = 0
spaceItr = 4 // n - (rowItr + 1)
starItr = 1 // rowItr + 1
// case 2
rowItr = 1
spaceItr = 3 // n - (rowItr + 1)
starItr = 2 // rowItr + 1
n = 5
for (let rowItr = 0; rowItr < n; rowItr++) {
for(let itrSpaces = 0 ; itrSpaces < n - (rowItr + 1) ; itrSpaces++) {
}
for(let starItr = 0 ; starItr < rowItr + 1 ; starItr++) {
}
}
*/