logo

String repeat

Write a function that accepts an integer n and a string s as parameters, and returns a string of s repeated exactly n times.


My code:

function repeatStr(n, s) {
                        let result = '';
                        for (let i = 0; i < n; i++) {
                          result += s;
                        }
                        return result;
                       } 
                    


And that's the best solution among all users:

function repeatStr (n, s) {
                        return s.repeat(n);
                      }
                    

New things I learned today: