From 0c2c81674653842bcd5a1b3275df34c14c546182 Mon Sep 17 00:00:00 2001 From: stellar-function-e8f8 Date: Mon, 29 Mar 2021 00:59:37 +0000 Subject: [PATCH] Done. --- arrays.js | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/arrays.js b/arrays.js index e69de29bb..3c5761d2f 100644 --- a/arrays.js +++ b/arrays.js @@ -0,0 +1,36 @@ +var chocolateBars = ["snickers", "hundred grand", "kitkat", "skittles"]; + +function addElementToBeginningOfArray(chocolateBars, element){ + return [element, ...chocolateBars]; +} +function destructivelyAddElementToBeginningOfArray(chocolateBars, element){ + chocolateBars.unshift(element); + return chocolateBars; +} +function addElementToEndOfArray(chocolateBars, element){ + return [...chocolateBars, element]; +} + +function destructivelyAddElementToEndOfArray(chocolateBars, element){ + chocolateBars.push(element); + return chocolateBars; +} +function accessElementInArray(chocolateBars, index){ +return chocolateBars[index]; +} + +function destructivelyRemoveElementFromBeginningOfArray(chocolateBars){ + chocolateBars.shift(); + return chocolateBars; +} + +function removeElementFromBeginningOfArray(chocolateBars){ +return chocolateBars.slice(1); +} +function destructivelyRemoveElementFromEndOfArray(chocolateBars){ + chocolateBars.pop(); + return chocolateBars; +} +function removeElementFromEndOfArray(chocolateBars){ +return chocolateBars.slice(0, chocolateBars.length -1); +}