From b6e97b454ff59f44cc448bb0e5eefc20aa7941e9 Mon Sep 17 00:00:00 2001 From: Rebecca Sorrell Date: Tue, 12 Jan 2021 20:12:04 +0000 Subject: [PATCH] Done. --- arrays.js | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/arrays.js b/arrays.js index e69de29bb2d..90f0f3165ec 100644 --- a/arrays.js +++ b/arrays.js @@ -0,0 +1,41 @@ +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); +} \ No newline at end of file