forked from AlreadyBored/basic-js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextended-repeater.js
More file actions
30 lines (27 loc) · 982 Bytes
/
Copy pathextended-repeater.js
File metadata and controls
30 lines (27 loc) · 982 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
module.exports = function repeater(str, options) {
repeatTimes = 'repeatTimes' in options ? options.repeatTimes : 0;
separator = 'separator' in options ? options.separator : '+';
addition = 'addition' in options ? options.addition : '';
additionRepeatTimes = 'additionRepeatTimes' in options ? options.additionRepeatTimes : 0;
additionSeparator = 'additionSeparator' in options ? options.additionSeparator : '|';
outstring = '';
let i = 0;
do {
i++;
if (i > 1) {
outstring = outstring + separator;
}
let add_str = '';
let j = 0;
do {
j++;
if (j > 1) {
add_str = add_str + additionSeparator;
}
add_str = add_str + addition
} while (j < additionRepeatTimes);
outstring = outstring + str + add_str;
} while (i < repeatTimes);
return outstring;
// remove line with error and write your code here
};