-
-
Save AliceWonderland/9e1a4bd4264bc909ee45302f9fcc96d6 to your computer and use it in GitHub Desktop.
5.3 My Unshift created by smillaraaq - https://repl.it/HET3/2
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 myUnshift (arr,num) { | |
| arr.splice(0,0,num); | |
| return arr; | |
| } | |
| console.log(myUnshift([1,3,4],2)); | |
| function myUnshift (arr,num) { | |
| var tempArray=[num]; | |
| for(var i=tempArray.length;i<=arr.length;i++){ | |
| tempArray[i]=arr[i-1]; | |
| } | |
| return arr = tempArray; | |
| } | |
| console.log(myUnshift([1,3,4],2)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment