1let labels = [];
2repeat(5, i => {
3 labels.push(`Unit ${i + 1}`);
4});
5console.log(labels);
6// → ["Unit 1", "Unit 2", "Unit 3", "Unit 4", "Unit 5"]
1// hey buddy, here are different implementations, choose your favourite !!
2
3
4// best implementation
5repeatStr = (n, s) => s.repeat(n);
6
7
8// short
9function repeatStr(n, s) {
10 return s.repeat(n);
11}
12
13
14// without using repeat
15function repeatStr(n, s) {
16 var str = "";
17 for (var i = 0; i < n; i++) str += s;
18 return str;
19}