From 1388d24ab466c087c14596e87d243dddd586e906 Mon Sep 17 00:00:00 2001 From: Mike Date: Tue, 6 May 2025 14:11:13 -0400 Subject: [PATCH 1/4] Destructive adding functions complete --- index.js | 10 +++++++++- package.json | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 132693a35c..2d51f86f0e 100644 --- a/index.js +++ b/index.js @@ -1 +1,9 @@ -// Write your solution here! +const cats = ["Milo", "Otis", "Garfield"] + +const destructivelyAppendCat = (catToAppend) => { + cats.push(catToAppend) +} + +const destructivelyPrependCat = (catToPrepend) => { + cats.unshift(catToPrepend) +} \ No newline at end of file diff --git a/package.json b/package.json index 1e0dc2b37d..d9efe32615 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "JavaScript Data Structures Arrays Lab for Learn.co", "main": "index.js", "scripts": { - "test": "mocha --timeout 5000 -R mocha-multi --reporter-options spec=-,json=.results.json" + "test": "mocha --timeout 5000 --bail -R mocha-multi --reporter-options spec=-,json=.results.json" }, "repository": { "type": "git", From c5eb9a9a171e12208fb97e9c1323f5601170580d Mon Sep 17 00:00:00 2001 From: Mike Date: Tue, 6 May 2025 14:12:32 -0400 Subject: [PATCH 2/4] Destructive removing functions done --- index.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/index.js b/index.js index 2d51f86f0e..91ee9107a3 100644 --- a/index.js +++ b/index.js @@ -6,4 +6,12 @@ const destructivelyAppendCat = (catToAppend) => { const destructivelyPrependCat = (catToPrepend) => { cats.unshift(catToPrepend) +} + +const destructivelyRemoveLastCat = () => { + cats.pop(); +} + +const destructivelyRemoveFirstCat = () => { + cats.shift(); } \ No newline at end of file From ff0dacd6e04f4f4d98134ffb558d98286ad49107 Mon Sep 17 00:00:00 2001 From: Mike Date: Tue, 6 May 2025 14:14:15 -0400 Subject: [PATCH 3/4] Nondestructively add functions complete --- index.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/index.js b/index.js index 91ee9107a3..004aaf8d41 100644 --- a/index.js +++ b/index.js @@ -14,4 +14,12 @@ const destructivelyRemoveLastCat = () => { const destructivelyRemoveFirstCat = () => { cats.shift(); +} + +const appendCat = (catToAppend) => { + return [...cats, catToAppend] +} + +const prependCat = (catToPrepend) => { + return [catToPrepend, ...cats] } \ No newline at end of file From 1e871ffcf46f5873fe7bca7910d9358e42b8a533 Mon Sep 17 00:00:00 2001 From: Mike Date: Tue, 6 May 2025 14:15:23 -0400 Subject: [PATCH 4/4] Nondestructively remove functions complete --- index.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/index.js b/index.js index 004aaf8d41..55ecc8fa3c 100644 --- a/index.js +++ b/index.js @@ -22,4 +22,12 @@ const appendCat = (catToAppend) => { const prependCat = (catToPrepend) => { return [catToPrepend, ...cats] +} + +const removeLastCat = () => { + return cats.slice(0, -1) +} + +const removeFirstCat = () => { + return cats.slice(1) } \ No newline at end of file