-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path08.js
More file actions
123 lines (81 loc) · 2.82 KB
/
Copy path08.js
File metadata and controls
123 lines (81 loc) · 2.82 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
105
106
107
108
109
110
111
112
113
114
class Str {
static lower(x){
console.log(x.toLowerCase());
}
static uppper(x){
console.log(x.toUpperCase());
}
static capitalize(x){
console.log(x.toLowerCase().split(' ').map((s) => s.charAt(0).toUpperCase() + s.substring(1)).join(' '));
}
static reverse(x){
let splitstring = x.split('').reverse().join('');
console.log(splitstring);
}
static contains(x,y){
let obj = 'object';
if (typeof(y) === obj){
for (let i=0; i<= y.length-1; i++){
if (x.includes(y[i]) === true){
console.log(true);
break;
} else {
console.log(false);
}
}
}
else {
console.log(x.includes(y));
}
}
static random(x=16){
let result= '';
let huruf = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
let panjanghuruf = huruf.length;
if (x !== null && typeof(x) === 'number'){
for ( let i=0; i < x; i++) {
result += huruf.charAt(Math.floor(Math.random() * panjanghuruf));
}
console.log(result);
} else {
console.log('Masukan angka slur');
}
}
static count(x){
console.log(x.length);
}
static countWords(x){
console.log(x.split(' ').length);
}
static trim(text, length, ending){
if(length == null){
length = 100;
}
if (ending == null){
ending= '...';
}
if (text.length > length){
let result = text.substring(0, length - ending.length) + ending;
console.log(result);
}else {
console.log(text);
}
}
}
let text =`Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.`;
Str.lower('Makan');
Str.uppper('malam');
Str.capitalize('saya ingin makan');
Str.reverse('kasur');
Str.contains('Saya ingin makan sate', 'makan');
Str.contains('Saya ingin makan sate', 'rujak');
Str.contains('Saya ingin makan sate', ['sampah','rujak']);
Str.random();
Str.random(6);
Str.random(32);
Str.count('lorem ipsum');
Str.countWords('lorem ipsum');
Str.trim('Less than 100 character');
Str.trim(text);
Str.trim(text,20);
Str.trim(text,20,'----')