From 76749ef86363b02e7af21fbb60b4853e11891f95 Mon Sep 17 00:00:00 2001 From: Anthony Phillips Date: Wed, 8 May 2024 09:11:43 -0400 Subject: [PATCH] Create functions for adding elements to array --- index.js | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 132693a35c..88357d63db 100644 --- a/index.js +++ b/index.js @@ -1 +1,33 @@ -// Write your solution here! +const cats = ["Milo", "Otis", "Garfield"]; + +function destructivelyAppendCat (name) { + cats.push(name); +} + +function destructivelyPrependCat (name) { + cats.unshift(name); +} + +function destructivelyRemoveLastCat () { + cats.pop(); +} + +function destructivelyRemoveFirstCat () { + cats.shift(); +} + +function appendCat (name) { + return [...cats, name]; +} + +function prependCat (name) { + return [name, ...cats]; +} + +function removeLastCat () { + return cats.slice(0, cats.length - 1); +} + +function removeFirstCat () { + return cats.slice(1); +}