Skip to content

Instantly share code, notes, and snippets.

@mallorywhitman
Created July 11, 2019 03:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mallorywhitman/b2abf93f994ac3aa2918e72c09689221 to your computer and use it in GitHub Desktop.
Save mallorywhitman/b2abf93f994ac3aa2918e72c09689221 to your computer and use it in GitHub Desktop.
// ♥ learn
> javascript-arrays@0.1.0 test /home/balanced-forum-1693/javascript-arrays-bootcamp-prep-001
> mocha -R mocha-multi --reporter-options nyan=-,json=.results.json
15 -_,------,
3 -_| /\_/\
0 -^|__( x .x)
- "" ""
15 passing (619ms)
3 failing
1) arrays addElementToBeginningOfArray(array, element) adds an element to thebeginning of an array:
AssertionError: expected [ 'element', 1 ] to deeply equal [ 'foo', 1 ]
+ expected - actual
[
- "element"
+ "foo"
1
]
at Context.it (test/arrays-test.js:21:59)
2) arrays destructivelyAddElementToBeginningOfArray(array, element) adds an element to the beginning of an array:
AssertionError: expected 2 to deeply equal [ 'foo', 1 ]
at Context.it (test/arrays-test.js:35:72)
3) arrays destructivelyAddElementToEndOfArray(array, element) adds an elementto the end of an array:
AssertionError: expected 2 to deeply equal [ 1, 'foo' ]
at Context.it (test/arrays-test.js:63:66)
var chocolateBars = ["snickers", "hundred grand", "kitkat", "skittles"]
function addElementToBeginningOfArray(array,element){
return ["element", ...array];
}
function destructivelyAddElementToBeginningOfArray(array,element){
var alteredArray = array.unshift(element);
return alteredArray;
}
function addElementToEndOfArray(array,element){
var newArray = [...array,element];
return newArray;
}
function destructivelyAddElementToEndOfArray(array,element){
return array.push(element);
}
function accessElementInArray(array,index){
return array[index];
}
function destructivelyRemoveElementFromBeginningOfArray(array){
var shiftedArray = array.shift();
return array;
}
function removeElementFromBeginningOfArray(array){
var slicedArray = array.slice(1);
return slicedArray;
}
function destructivelyRemoveElementFromEndOfArray(array){
var popedArray = array.pop();
return array;
}
function removeElementFromEndOfArray(array){
var lastElementSliced = array.slice(0, array.length-1);
return lastElementSliced;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment