Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
144 changes: 144 additions & 0 deletions .results.json
Original file line number Diff line number Diff line change
@@ -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": {}
}
]
}
42 changes: 41 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -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
}