-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
104 lines (103 loc) · 2.42 KB
/
Copy pathscript.js
File metadata and controls
104 lines (103 loc) · 2.42 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
class IntBuilder{
constructor(num) {
this.num = num;
}
static random(min, max){return Math.floor(Math.random() * (max - min + 1) ) + min;}
plus(...n){
for(let i=0; i<=n.length-1; i=i+1){
this.num = this.num + n[i];
}
console.log(this.num);
return this;
}
minus(...n){
for(let i=0; i<=n.length-1; i=i+1){
this.num = this.num - n[i];
}
console.log(this.num);
return this;
}
multiply(n){
this.num = this.num * n;
console.log(this.num);
return this;
}
divide(n){
this.num = this.num / n;
console.log(this.num);
return this;
}
mod(n){
this.num = this.num % n;
console.log(this.num);
return this;
}
get(){
console.log(this.num);
return this;
}
}
class StringBuilder{
constructor(str){
this.str = str;
}
plus(...n){
this.str = [this.str];
this.str.push(...n);
this.str = this.str.join("");
console.log(this.str);
return this;
}
minus(n){
this.str = [...this.str];
for(let i=1; i<=n; i++){
this.str.pop();
}
this.str = this.str.join("");
console.log(this.str);
return this;
}
multiply(n){
this.str = [this.str];
for(let i=1; i<=n-1; i++){
this.str.push(this.str[0]);
}
this.str = this.str.join("");
console.log(this.str);
return this;
}
divide(n){
let strlen = this.str.length;
let k = Math.floor(strlen / n);
this.str = [...this.str];
for(let i=1; i<=strlen-n; i++){
this.str.pop();
}
this.str = this.str.join("");
console.log(this.str);
return this;
}
remove(n){
this.str = [...this.str];
const index = this.str.indexOf(n);
for(let i=0; i<=this.str.length; i++){
if (index > -1) {
this.str.splice(index, 1);
}
}
this.str = this.str.join("");
console.log(this.str);
return this;
}
sub(from, n){
this.str = [...this.str];
this.str = this.str.splice(from, n);
this.str = this.str.join("");
console.log(this.str);
return this;
}
get(){
console.log(this.str);
return this;
}
}