Skip to content
Open

Done #5721

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
45 changes: 45 additions & 0 deletions arrays.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
var chocolateBars = ["snickers", "hundred grand", "kitkat", "skittles"];
var addedChocolateBar = "foo";

function addElementToBeginningOfArray(chocolateBars, addedChocolateBar) {
var moreChocolateBars = [addedChocolateBar,...chocolateBars]
return moreChocolateBars;
}

function destructivelyAddElementToBeginningOfArray(chocolateBars, addedChocolateBar) {
chocolateBars.unshift(addedChocolateBar);
return chocolateBars;
}

function addElementToEndOfArray(chocolateBars, addedChocolateBar) {
var moreChocolateBars = [...chocolateBars,addedChocolateBar]
return moreChocolateBars;
}

function destructivelyAddElementToEndOfArray(chocolateBars, addedChocolateBar) {
chocolateBars.push(addedChocolateBar);
return chocolateBars;
}

function accessElementInArray(array, index) {
return array[index];
}

function destructivelyRemoveElementFromBeginningOfArray(chocolateBars) {
chocolateBars.shift();
return chocolateBars;
}

function removeElementFromBeginningOfArray (chocolateBars) {
return chocolateBars.slice(1);
}

function destructivelyRemoveElementFromEndOfArray(chocolateBars) {
chocolateBars.pop();
return chocolateBars;
}

function removeElementFromEndOfArray(chocolateBars) {
chocolateBars = chocolateBars.slice(0, chocolateBars.length - 1);
return chocolateBars;
}