Skip to content

Instantly share code, notes, and snippets.

@spideron
spideron / String.prototype.wiFormat
Created February 7, 2013 19:36
string format (C like)
String.prototype.wiFormat = function () {
var pattern = /\{\d+\}/g;
var args = arguments;
return this.replace(pattern, function (capture) {
return args[capture.match(/\d+/)];
});
};
@spideron
spideron / String.prototype.shuffle
Last active December 12, 2015 06:59
shuffle string
String.prototype.shuffle = function(size){
var arr = this.split('');
for(var j, x, i = arr.length; i; j = parseInt(Math.random() * i), x = arr[--i], arr[i] = arr[j], arr[j] = x){};
arr = arr.join('');
return size ? arr.substr(0, Math.min(size, arr.length-1)) : arr;
};