Bootcamp Prep – JavaScript Arrays

Bootcamp Prep – JavaScript Arrays

This covers the initial lab in the Data Structures section (within JavaScript Fundamentals module) of’s Bootcamp Prep. Not to be confused with “JavaScript Arrays Lab.”

JavaScript Arrays

Task: Do a lot with arrays. Add elements to beginning and end (safely and destructively). Access the elements and remove elements from beginning and end (safely and destructively).

var chocolateBars = ["snickers", "hundred grand", "kitkat", "skittles"];
//var candyString = "foo"

function addElementToBeginningOfArray(chocolateBars, candyString){
  return [candyString, ...chocolateBars];

function destructivelyAddElementToBeginningOfArray(chocolateBars, candyString){
  return chocolateBars;

function addElementToEndOfArray(chocolateBars, candyString){
  return [...chocolateBars, candyString];

function destructivelyAddElementToEndOfArray(chocolateBars, candyString){
  return chocolateBars;

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

function destructivelyRemoveElementFromBeginningOfArray(chocolateBars){
  return chocolateBars;

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

function destructivelyRemoveElementFromEndOfArray(chocolateBars){
  return chocolateBars;

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

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s