-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathcounterstring.js
More file actions
35 lines (29 loc) · 756 Bytes
/
counterstring.js
File metadata and controls
35 lines (29 loc) · 756 Bytes
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
javascript:
(
()=> {
function buildString (string_length, delimiter) {
while (string_length > 1) {
chunk = string_length.toString() + delimiter.toString();
theString = chunk + theString;
string_length -= chunk.length;
}
if ( string_length == 1 ) {
theString = delimiter.toString() + theString;
}
return(theString);
}
let delimiter = "*";
let theString = "";
the_message = prompt("Length (,delimiter)");
if (the_message != null) {
if (result = the_message.match(/^(\d+)/)) {
string_length = parseInt(result[1]);
}
if (result = the_message.match(/^\d+,(.)$/)) {
delimiter = result[1].toString();
}
theString = buildString(string_length, delimiter);
navigator.clipboard.writeText(theString);
}
}
)();