Created
April 12, 2017 05:29
-
-
Save anonymous/5f01cbb3e447748f8c51a26547b5b4f4 to your computer and use it in GitHub Desktop.
5.6 My Slice created by smillaraaq - https://repl.it/HEZ7/1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function mySlice (arr,begin,end) { | |
| var newArr = []; | |
| var start = (begin)?begin:0; | |
| start = (begin<0)?arr.length+begin:start; | |
| var terminate = (end)?end:arr.length-1; | |
| for (let i = start ; i <= terminate ; i++){ | |
| newArr.push(arr[i]); | |
| } | |
| return console.log(newArr); | |
| } | |
| mySlice([1,2,3]) // => [1,2,3] | |
| mySlice([1,2,3], 1) // => [2,3] | |
| mySlice([1,2,3], 1, 2) // => [2] | |
| mySlice([1,2,3], -1) // => [3] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment