-
-
Save wifelette/57e7ea0f9b52204aa384ec3c9343a6cb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ♥ learn | |
> [email protected] 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) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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