Skip to content

Instantly share code, notes, and snippets.

Created April 12, 2017 05:29
Show Gist options
  • Select an option

  • Save anonymous/421d891ca8bf8372f1bfb97b3ec63272 to your computer and use it in GitHub Desktop.

Select an option

Save anonymous/421d891ca8bf8372f1bfb97b3ec63272 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