Skip to content

Commit e3f5559

Browse files
committed
Merge branch 'master' of github.com:learn-co-curriculum/javascript-arrays
2 parents b80266a + 3729c04 commit e3f5559

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ But now what if we want to make a tomato sauce? Well, we already have garlic and
3131

3232
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.
3333

34-
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.
34+
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.
3535

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

@@ -58,7 +58,7 @@ var tomatoSauceIngredients = [
5858

5959
## Creation
6060

61-
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**.
61+
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**.
6262

6363
```javascript
6464
var myArray = [element0, element1, ..., elementN];

test/arrays-test.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ describe('arrays', () => {
2626

2727
addElementToBeginningOfArray(array, 'foo')
2828

29-
expect(array).to.eql(array)
29+
expect(array).to.eql([1])
3030
})
3131
})
3232

@@ -77,13 +77,37 @@ describe('arrays', () => {
7777
expect(accessElementInArray([1, 2, 3], 2)).to.equal(3)
7878
})
7979
})
80+
81+
describe('destructivelyRemoveElementFromBeginningOfArray(array)', ()=>{
82+
it('returns the `array` with the first element removed', () => {
83+
expect(destructivelyRemoveElementFromBeginningOfArray([1, 2, 3])).to.eql([2, 3])
84+
})
85+
86+
it('did not make a copy of the array when removing the first element', ()=>{
87+
const array = [1, 2, 3];
88+
destructivelyRemoveElementFromBeginningOfArray(array);
89+
expect(array).to.eql([2, 3]);
90+
})
91+
})
8092

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

99+
describe('destructivelyRemoveElementFromEndOfArray(array)', () => {
100+
it('returns the `array` with the last element removed', () => {
101+
expect(destructivelyRemoveElementFromEndOfArray([1, 2, 3])).to.eql([1, 2])
102+
})
103+
104+
it('did not make a copy of the array when removing the last element', ()=>{
105+
const array = [1, 2, 3];
106+
destructivelyRemoveElementFromEndOfArray(array);
107+
expect(array).to.eql([1, 2]);
108+
})
109+
})
110+
87111
describe('removeElementFromEndOfArray(array)', () => {
88112
it('removes the last element from the `array`', () => {
89113
expect(removeElementFromEndOfArray([1, 2, 3])).to.eql([1, 2])

0 commit comments

Comments
 (0)