'use strict';


module.exports = function () {
    var result = '';
    var idx = 0;

    for (var current = 1; current < arguments.length && idx !== -1; current++) {
        idx = arguments[0].indexOf('%');
        if (arguments[0][idx + 1] === 's' || arguments[0][idx + 1] === 'd') {
            result += arguments[0].slice(0, idx);
            result += arguments[current];
            arguments[0] = arguments[0].slice(idx + 2);
        } else {
            current--;
        }
    }

    result += arguments[0];

    return result;
};

'use strict';


module.exports = function () {
    var result = '';
    var idx = 0;
    var lastIdx = -1;

    for (var current = 1; current < arguments.length && idx !== -1; current++) {
        idx = arguments[0].indexOf('%', lastIdx);
        if (arguments[0][idx + 1] === 's' || arguments[0][idx + 1] === 'd') {
            result += arguments[0].substring(lastIdx, idx);
            result += arguments[current];
            lastIdx = idx + 2;
        } else {
            current--;
        }
    }

    result += arguments[0].substring(lastIdx);

    return result;
};

Use substring instead of slicing - double speedup!
Use substring instead of slicing - double speedup!

                      pff
       1,997,810 op/s » tiny (production)
         621,845 op/s » short (production)
       1,386,780 op/s » tiny (5)
         720,355 op/s » short (10)
          77,338 op/s » medium (100)

                      printf
          58,001 op/s » tiny (production)
          22,922 op/s » short (production)
          53,702 op/s » tiny (5)
          30,997 op/s » short (10)
           3,570 op/s » medium (100)

                      printf2
       1,085,254 op/s » tiny (production)
         874,416 op/s » short (production)
         981,879 op/s » tiny (5)
         560,251 op/s » short (10)
          68,190 op/s » medium (100)
