Skip to content

Instantly share code, notes, and snippets.

@fakefarm
Last active June 8, 2017 20:35
Show Gist options
  • Save fakefarm/a61223c5adad9d4dc348c81db48aceea to your computer and use it in GitHub Desktop.
Save fakefarm/a61223c5adad9d4dc348c81db48aceea to your computer and use it in GitHub Desktop.
1. Travis
// My Comments start with '//' so that you can paste this into 'chrome developer console' in your broswer to test it out
// '=>'' is the return values after running the commands;
// 1. set the array
var testArr = [1,2,3]
// 2. use the array function push(n) to add something to end of array.
// Note that it returns the size of the arrry (not the value)
testArr.push(4)
// => 4
// 3. Check the array that it does indeed have 4 items
testArr
// => [1, 2, 3, 4]
// 4. use pop(n) to remove items from back of array
// The '3' is how many things are left
testArr.pop(1)
// => 3
// 5. see, 3 things.
testArr
// => [1, 2, 3]
// 6. use unshift(N) to add things to the front of the Array
// Unshift returns size of array (4)
testArr.unshift('A')
// => 4
// 7. Now, Array has front thing but not back thing.
testArr
=> ['A', 1, 2, 3]
// 8. Your custom function will make use of these kinds of methods. For example -
function nextInLine(array, item) {
array.unshift
return array[0]
// This is an example not actual solution :-)
// But let me know if you need help.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment