1 var baseToString = require('../internal/baseToString');
3 /* Native method references for those with the same name as other `lodash` methods. */
4 var nativeFloor = Math.floor,
5 nativeIsFinite = global.isFinite;
8 * Repeats the given string `n` times.
13 * @param {string} [string=''] The string to repeat.
14 * @param {number} [n=0] The number of times to repeat the string.
15 * @returns {string} Returns the repeated string.
27 function repeat(string, n) {
29 string = baseToString(string);
31 if (n < 1 || !string || !nativeIsFinite(n)) {
34 // Leverage the exponentiation by squaring algorithm for a faster repeat.
35 // See https://en.wikipedia.org/wiki/Exponentiation_by_squaring for more details.
40 n = nativeFloor(n / 2);
47 module.exports = repeat;