Skip to content

Commit

Permalink
Merge branch 'master' of github.com:learn-co-curriculum/javascript-ar…
Browse files Browse the repository at this point in the history
…rays
  • Loading branch information
gj committed Aug 20, 2017
2 parents b80266a + 3729c04 commit e3f5559
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ But now what if we want to make a tomato sauce? Well, we already have garlic and

This is an admittedly contrived example, but it goes to show that we can't just put everything in a variable and hope to remember what order things should go in. It also shows that sometimes it would be helpful to be able to group like items together.

In JavaScript, we can group like items in an object (well, everything in JavaScript is an object — but more on that some other time) called an _array_. And array is an ordered list of items (called "elements" of the array) separated by commas.
In JavaScript, we can group like items in an object (well, everything in JavaScript is an object — but more on that some other time) called an _array_. An array is an ordered list of items (called "elements" of the array) separated by commas.

Arrays look like this: `[1, 2, 3]`.

Expand All @@ -58,7 +58,7 @@ var tomatoSauceIngredients = [

## Creation

JavaScript arrays can contain any types of values and they can be of mixed types. You can create arrays in two different ways, the most common of which is to list values in a pair of square brackets. These are called **array literals**.
JavaScript arrays can contain all types of values and they can be of mixed types. You can create arrays in two different ways, the most common of which is to list values in a pair of square brackets. These are called **array literals**.

```javascript
var myArray = [element0, element1, ..., elementN];
Expand Down
26 changes: 25 additions & 1 deletion test/arrays-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('arrays', () => {

addElementToBeginningOfArray(array, 'foo')

expect(array).to.eql(array)
expect(array).to.eql([1])
})
})

Expand Down Expand Up @@ -77,13 +77,37 @@ describe('arrays', () => {
expect(accessElementInArray([1, 2, 3], 2)).to.equal(3)
})
})

describe('destructivelyRemoveElementFromBeginningOfArray(array)', ()=>{
it('returns the `array` with the first element removed', () => {
expect(destructivelyRemoveElementFromBeginningOfArray([1, 2, 3])).to.eql([2, 3])
})

it('did not make a copy of the array when removing the first element', ()=>{
const array = [1, 2, 3];
destructivelyRemoveElementFromBeginningOfArray(array);
expect(array).to.eql([2, 3]);
})
})

describe('removeElementFromBeginningOfArray(array)', () => {
it('removes the first element from the `array`', () => {
expect(removeElementFromBeginningOfArray([1, 2, 3])).to.eql([2, 3])
})
})

describe('destructivelyRemoveElementFromEndOfArray(array)', () => {
it('returns the `array` with the last element removed', () => {
expect(destructivelyRemoveElementFromEndOfArray([1, 2, 3])).to.eql([1, 2])
})

it('did not make a copy of the array when removing the last element', ()=>{
const array = [1, 2, 3];
destructivelyRemoveElementFromEndOfArray(array);
expect(array).to.eql([1, 2]);
})
})

describe('removeElementFromEndOfArray(array)', () => {
it('removes the last element from the `array`', () => {
expect(removeElementFromEndOfArray([1, 2, 3])).to.eql([1, 2])
Expand Down

0 comments on commit e3f5559

Please sign in to comment.