From cf38be89c21750801b96c6cf6c32fe0ece487671 Mon Sep 17 00:00:00 2001 From: Jen Kelly Date: Fri, 9 May 2025 16:35:16 -0400 Subject: [PATCH] Complete lab --- index.js | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 132693a35c..94a98822cb 100644 --- a/index.js +++ b/index.js @@ -1 +1,29 @@ -// Write your solution here! +const cats = ["Milo", "Otis", "Garfield"]; + +destructivelyAppendCat = (name) => cats.push(name); + +destructivelyPrependCat = (name) => cats.unshift(name); + +destructivelyRemoveLastCat = (name) => cats.pop(name); + +destructivelyRemoveFirstCat = (name) => cats.shift(name); + +function appendCat(name) { + let copyOfAppendCat; + return (copyOfAppendCat = [...cats, name]); +} + +function prependCat(name) { + let copyOfPrependCat; + return (copyOfPrependCat = [name, ...cats]); +} + +function removeLastCat() { + let copyOfRemoveLastCat; + return (copyOfRemoveLastCat = cats.slice(0, cats.length - 1)); +} + +function removeFirstCat() { + let copyOfRemoveFirstCat; + return (copyOfRemoveFirstCat = cats.slice(1)); +}