JSFiddle - React, Tailwind, and code Playground
by Matthew Vukomanovic
JavaScript
function spliceArray(array, index, howmany, source, start, end) {
var arguments;
if( source !== undefined ){
arguments = source.slice(start, end);
arguments.splice(0,0, index, howmany);
} else{
arguments = [index, howmany];
}
return Array.prototype.splice.apply(array, arguments)
}
Array.prototype.spliceArray = function(index, howmany, source, start, end) {
return spliceArray(this, index, howmany, source, start, end);
}
function runTest(index,howmany, start,end){
var array = [1,2,3,4,5,6,7,8];
var source = [-1,-2,-3,-4,-5];
console.log("calling spliceArray with : "
+ "array = " + array + ";"
+ "index = " + index + ";"
+ "howmany = " + howmany + ";"
+ "source = " + source + ";"
+ "start = " + start + ";"
+ "end = " + end + ";");
//var result = spliceArray(array, index, howmany, source, start, end);
var result = array.spliceArray(index, howmany, source, start, end);
console.log("results in : "
+ "return = " + result + ";"
+ "array = " + array + ";"
+ "source = " + source + ";"
);
}
runTest();
runTest(1);
runTest(2);
runTest(3);
runTest(1,1);
runTest(1,1,1);
runTest(1,1,1,2);
runTest(1,5,2,5);