ello
str_splice("hello", 0, 1);
var str = "hello";
var res = str_splice(str, 0, 1);
function str_splice(str, index, len) {
var parms = [...arguments];
var res = "";
str = str.split("");
for (var i = 3; i < parms.length; i++) {
res += parms[i];
}
str.splice(index, len, res);
str = str.join("");
return str;
}
console.log(res);
helo
str_splice("hello", 0, 1);
var str = "hello";
var res = str_splice(str, 2, 1);
function str_splice(str, index, len) {
var parms = [...arguments];
var res = "";
str = str.split("");
for (var i = 3; i < parms.length; i++) {
res += parms[i];
}
str.splice(index, len, res);
str = str.join("");
return str;
}
console.log(res);
heo
str_splice("hello", 0, 1);
var str = "hello";
var res = str_splice(str, 2, 2);
function str_splice(str, index, len) {
var parms = [...arguments];
var res = "";
str = str.split("");
for (var i = 3; i < parms.length; i++) {
res += parms[i];
}
str.splice(index, len, res);
str = str.join("");
return str;
}
console.log(res);
qello
var res = str_splice("hello", 0, 1, "q");
function str_splice(str, index, len,newStr) {
for (var i = 0; i < str.length; i++) {
if (i >= index && i < len + index) {
newStr = newStr===undefined ?'': newStr;
ren = ren + newStr
continue
}
ren = ren + str[i]
}
return ren
}
qhello
var res = str_splice("hello", 0, 0, "q");
function str_splice(str, index, len,newStr) {
if (typeof str !== 'string') throw new Error('param1 must be string')
var ren = '';
if (typeof len === 'undefined') {
for(var i =0;i<str.length;i++){
if(i>=index){
continue
}
ren = ren + str[i]
}
return ren
}
for (var i = 0; i < str.length; i++) {
if (i >= index && i < len + index) {
newStr = newStr===undefined ?'': newStr;
ren = ren + newStr
continue
}
if(len === 0 & index === i){
ren = ren + newStr
}
ren = ren + str[i]
}
return ren
}