Array.prototype.myslice = function(start,end){
if(start&&end){
start = start<0?start = this.length+start:start
end = end<0?end = this.length+end:end
}
if(!start) start = 0
if(!end) end = this.length
let res=[];
for(let i=start;i<end;i++){
res.push(this[i])
}
return res
}
const arr = [1,2,3,4,5,6,7,8,9]
console.log(arr.myslice(4,7))
console.log(arr.myslice(-4,-2))
console.log(arr.myslice(2))
String.prototype.myslice = function(start,end){
if(start&&end){
start = start<0?start = this.length+start:start
end = end<0?end = this.length+end:end
}
if(!start) start = 0
if(!end) end = this.length
let res =''
for(let i=start;i<end;i++){
res +=this[i]
}
return res
}
const str = 'hello javascript'
console.log(str.myslice(4,9))
console.log(str.myslice(-6,-3))
console.log(str.myslice(3))
console