Skip to content

Instantly share code, notes, and snippets.

@McLarenCollege
Last active August 5, 2022 11:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save McLarenCollege/ae6b628b83034514d2fcce8dede0a3ce to your computer and use it in GitHub Desktop.
Save McLarenCollege/ae6b628b83034514d2fcce8dede0a3ce to your computer and use it in GitHub Desktop.
Exercise : Unshift Challenge

Write a function that inserts an element at the begining of an array and returns the modified array.

Note: You cannot create a new array

CODE TEMPLATE


let arr = [5,10,9];
function unshift(arr,newVal)
{
 // write your code here
}
console.log(unshift(arr,20)); // should print [20, 5,10, 9]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment