Skip to content

Commit d749f6a

Browse files
committed
Slice Method Added
1 parent 41752bf commit d749f6a

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

slice.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Array.prototype.ownSlice = function ownSlice (str, end) {
2+
const arr = this;
3+
const result = [];
4+
5+
if (Array.isArray(arr)) {
6+
const loopContinue = end > arr.length ? arr.length : end;
7+
for (let i = str; i < loopContinue; i++) {
8+
result.push(arr[i]);
9+
}
10+
}
11+
return result;
12+
}
13+
14+
const arr = [1,2,3,4,5];
15+
console.log(arr.ownSlice(2,4))

0 commit comments

Comments
 (0)