The Javascript splice only works with arrays. Is there similar method for strings? Or should I create my own custom function?
The substr(),
The second function's signature is identical to the Array.prototype.splice method.
function mutate(s) {
return function splice() {
var a = s.split('');
Array.prototype.splice.apply(a, arguments);
return a.join('');
};
}
mutate('101')(1, 1, '1');
I know there's already an accepted answer, but hope this is useful.