Skip to content

Instantly share code, notes, and snippets.

@AliceWonderland
Forked from anonymous/5.3 My Unshift.js
Created April 12, 2017 05:29
Show Gist options
  • Select an option

  • Save AliceWonderland/9e1a4bd4264bc909ee45302f9fcc96d6 to your computer and use it in GitHub Desktop.

Select an option

Save AliceWonderland/9e1a4bd4264bc909ee45302f9fcc96d6 to your computer and use it in GitHub Desktop.
5.3 My Unshift created by smillaraaq - https://repl.it/HET3/2
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