diff --git a/arrays.js b/arrays.js index e69de29bb2d..eacad3d4d5d 100644 --- a/arrays.js +++ b/arrays.js @@ -0,0 +1,32 @@ +var chocolateBars = ['snickers', 'hundred grand', 'kitkat', 'skittles'] +function addElementToBeginningOfArray(array, element){ + return [element, ...array] +} +function destructivelyAddElementToBeginningOfArray(array, element) { + array.unshift(element); + return array; +} +function addElementToEndOfArray(array, element){ + return [...array, element] +} +function destructivelyAddElementToEndOfArray(array, element){ + array.push(element) + return array +} +function accessElementInArray(array, index){ + return array[index] +} +function destructivelyRemoveElementFromBeginningOfArray(array){ + array.shift() + return array +} +function removeElementFromBeginningOfArray(array){ + return array.slice(1) +} +function destructivelyRemoveElementFromEndOfArray(array){ + array.pop() + return array +} +function removeElementFromEndOfArray(array){ + return array.slice(0, array.length - 1) +}