JSFiddle - React, Tailwind, and code Playground
HTML
Open the console to see test results
JavaScript
var abc = "123456789abcdefghijklmnopqrstuvwxyz";
var myString = "";
for(var i = 0; i< 2000; i++){
myString += abc;
}
String.prototype.splice = function(startIndex,length,insertString){
return this.substring(0,startIndex) + insertString + this.substring(startIndex + length);
};
String.prototype.mutate = function(){
var s = this;
return function splice() {
var a = s.split('');
Array.prototype.splice.apply(a, arguments);
return a.join('');
};
}
String.prototype.spliceSlice = function(index, count, add) {
// We cannot pass negative indexes dirrectly to the 2nd slicing operation.
if (index < 0) {
index = this.length + index;
if (index < 0) {
index = 0;
}
}
return this.slice(0, index) + (add || "") + this.slice(index + count);
}
var start = 0;
start = Date.now();
myString.mutate()(20,4000,"Hello World");
console.log("Kumar and Codys Mutated Curry: " + (Date.now()-start) + "ms")
start = Date.now();
myString.spliceSlice(20,4000,"Hello World");
console.log("Louis Splice Slice Method: " + (Date.now()-start) + "ms")
start = Date.now();
myString.splice(20,4000,"Hello World");
console.log("My Method: " + (Date.now()-start) + "ms")