diff --git a/.results.json b/.results.json new file mode 100644 index 0000000000..b8308da2d4 --- /dev/null +++ b/.results.json @@ -0,0 +1,144 @@ +{ + "stats": { + "suites": 11, + "tests": 9, + "passes": 9, + "pending": 0, + "failures": 0, + "start": "2025-03-18T01:59:48.572Z", + "end": "2025-03-18T01:59:49.250Z", + "duration": 678 + }, + "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": 1, + "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": 1, + "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": 2, + "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": 1, + "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": 1, + "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": 1, + "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": 2, + "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": 1, + "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..935815f583 100644 --- a/index.js +++ b/index.js @@ -1 +1,41 @@ -// Write your solution here! +let cats = ["Milo", "Otis", "Garfield"]; + +function destructivelyAppendCat(name) { + cats.push(name); + // function to append a cat destructively +} + +// function to remove the last cat destructively +function destructivelyRemoveLastCat() { + cats.pop(); +} + +function destructivelyPrependCat(name) { + cats.unshift(name); + // adds at cat to the beginning +} + +function destructivelyRemoveFirstCat() { + cats.shift(); + // removes the first cat +} + +function appendCat(name) { + return [...cats, name]; + // creates a new array with the new cat added at the end +} + +function prependCat(name) { + return [name, ...cats,]; + // creates a new array with 'name' at the beginning +} + +function removeLastCat() { + return cats.slice(0, -1); + // returns a new array without the last element +} + +function removeFirstCat() { + return cats.slice(1); + // returns a new array without modifying the original +} \ No newline at end of file