Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // возвращает форматированную строку, аналогичную той, что выводит console.log
- function sprtinf(s) {
- var a = Array.prototype.slice.call(arguments, 1)
- , v;
- return s.replace(/%(?:%|\d+([sdf]))/g, function (m, t) {
- if (m == '%%') return '%';
- if (!a.length) return m;
- v = a.shift();
- if (t == 'd') return parseInt(v);
- if (t == 'f') return parseFloat(v);
- return v;
- });
- }
- // как в C#, Python
- function format(s) {
- var a = Array.prototype.slice.call(arguments, 1);
- return s.replace(/\{(\d+)\}/g, function (m, i) {
- if (i >= a.length) return m;
- return a[i];
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment