From 7e1f2711ec8d18b0feb97930b134d74173c42a46 Mon Sep 17 00:00:00 2001 From: Thomas Regulski Date: Fri, 11 Dec 2020 14:00:42 +0000 Subject: [PATCH] Done. --- arrays.js | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/arrays.js b/arrays.js index e69de29bb2d..8490e1eceec 100644 --- a/arrays.js +++ b/arrays.js @@ -0,0 +1,41 @@ +var chocolateBars = ["snickers", "hundered grand", "kitkat", "skittles"]; + +function addElementToBeginningOfArray(array, element) { + return [element, ...array]; +} + +function addElementToEndOfArray(array, element) { + return [...array, element]; +} + +function destructivelyAddElementToBeginningOfArray(array, element) { + array.unshift(element); + return array; +} + +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); +}