diff --git a/.results.json b/.results.json new file mode 100644 index 0000000000..7adb22d5e7 --- /dev/null +++ b/.results.json @@ -0,0 +1,144 @@ +{ + "stats": { + "suites": 11, + "tests": 9, + "passes": 9, + "pending": 0, + "failures": 0, + "start": "2025-05-06T17:06:00.217Z", + "end": "2025-05-06T17:06:00.322Z", + "duration": 105 + }, + "tests": [ + { + "title": "is assigned an initial value of [\"Milo\", \"Otis\", \"Garfield\"]", + "fullTitle": "index.js cats is assigned an initial value of [\"Milo\", \"Otis\", \"Garfield\"]", + "duration": 0, + "currentRetry": 0, + "err": {} + }, + { + "title": "appends a cat to the end of the cats array", + "fullTitle": "index.js Array functions destructivelyAppendCat(name) appends a cat to the end of the cats array", + "duration": 0, + "currentRetry": 0, + "err": {} + }, + { + "title": "prepends a cat to the beginning of the cats array", + "fullTitle": "index.js Array functions destructivelyPrependCat(name) prepends a cat to the beginning of the cats array", + "duration": 0, + "currentRetry": 0, + "err": {} + }, + { + "title": "removes the last cat from the cats array", + "fullTitle": "index.js Array functions destructivelyRemoveLastCat() removes the last cat from the cats array", + "duration": 0, + "currentRetry": 0, + "err": {} + }, + { + "title": "removes the first cat from the cats array", + "fullTitle": "index.js Array functions destructivelyRemoveFirstCat() removes the first cat from the cats array", + "duration": 0, + "currentRetry": 0, + "err": {} + }, + { + "title": "appends a cat to the cats array and returns a new array, leaving the cats array unchanged", + "fullTitle": "index.js Array functions appendCat(name) appends a cat to the cats array and returns a new array, leaving the cats array unchanged", + "duration": 0, + "currentRetry": 0, + "err": {} + }, + { + "title": "prepends a cat to the cats array and returns a new array, leaving the cats array unchanged", + "fullTitle": "index.js Array functions prependCat(name) prepends a cat to the cats array and returns a new array, leaving the cats array unchanged", + "duration": 0, + "currentRetry": 0, + "err": {} + }, + { + "title": "removes the last cat in the cats array and returns a new array, leaving the cats array unchanged", + "fullTitle": "index.js Array functions removeLastCat() removes the last cat in the cats array and returns a new array, leaving the cats array unchanged", + "duration": 0, + "currentRetry": 0, + "err": {} + }, + { + "title": "removes the first cat from the cats array and returns a new array, leaving the cats array unchanged", + "fullTitle": "index.js Array functions removeFirstCat() removes the first cat from the cats array and returns a new array, leaving the cats array unchanged", + "duration": 0, + "currentRetry": 0, + "err": {} + } + ], + "pending": [], + "failures": [], + "passes": [ + { + "title": "is assigned an initial value of [\"Milo\", \"Otis\", \"Garfield\"]", + "fullTitle": "index.js cats is assigned an initial value of [\"Milo\", \"Otis\", \"Garfield\"]", + "duration": 0, + "currentRetry": 0, + "err": {} + }, + { + "title": "appends a cat to the end of the cats array", + "fullTitle": "index.js Array functions destructivelyAppendCat(name) appends a cat to the end of the cats array", + "duration": 0, + "currentRetry": 0, + "err": {} + }, + { + "title": "prepends a cat to the beginning of the cats array", + "fullTitle": "index.js Array functions destructivelyPrependCat(name) prepends a cat to the beginning of the cats array", + "duration": 0, + "currentRetry": 0, + "err": {} + }, + { + "title": "removes the last cat from the cats array", + "fullTitle": "index.js Array functions destructivelyRemoveLastCat() removes the last cat from the cats array", + "duration": 0, + "currentRetry": 0, + "err": {} + }, + { + "title": "removes the first cat from the cats array", + "fullTitle": "index.js Array functions destructivelyRemoveFirstCat() removes the first cat from the cats array", + "duration": 0, + "currentRetry": 0, + "err": {} + }, + { + "title": "appends a cat to the cats array and returns a new array, leaving the cats array unchanged", + "fullTitle": "index.js Array functions appendCat(name) appends a cat to the cats array and returns a new array, leaving the cats array unchanged", + "duration": 0, + "currentRetry": 0, + "err": {} + }, + { + "title": "prepends a cat to the cats array and returns a new array, leaving the cats array unchanged", + "fullTitle": "index.js Array functions prependCat(name) prepends a cat to the cats array and returns a new array, leaving the cats array unchanged", + "duration": 0, + "currentRetry": 0, + "err": {} + }, + { + "title": "removes the last cat in the cats array and returns a new array, leaving the cats array unchanged", + "fullTitle": "index.js Array functions removeLastCat() removes the last cat in the cats array and returns a new array, leaving the cats array unchanged", + "duration": 0, + "currentRetry": 0, + "err": {} + }, + { + "title": "removes the first cat from the cats array and returns a new array, leaving the cats array unchanged", + "fullTitle": "index.js Array functions removeFirstCat() removes the first cat from the cats array and returns a new array, leaving the cats array unchanged", + "duration": 0, + "currentRetry": 0, + "err": {} + } + ] +} \ No newline at end of file diff --git a/index.js b/index.js index 132693a35c..8b3db389b5 100644 --- a/index.js +++ b/index.js @@ -1 +1,33 @@ -// Write your solution here! +const cats = ["Milo", "Otis", "Garfield"]; + +function destructivelyAppendCat(name) { + return cats.push(name); +} + +function destructivelyPrependCat(name) { + return cats.unshift(name); +} + +function destructivelyRemoveLastCat() { + return cats.pop(); +} + +function destructivelyRemoveFirstCat() { + return 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); +} \ No newline at end of file