Skip to content

Commit b2d06e2

Browse files
ensure complete test coverage
1 parent e3f5559 commit b2d06e2

File tree

2 files changed

+32
-18
lines changed

2 files changed

+32
-18
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ iceCreams.slice(0, iceCreams.length - 1) // ["chocolate", "vanilla"]
260260
iceCreams // ["chocolate", "vanilla", "raspberry"]
261261
```
262262

263-
**TODO**: Define a function in `arrays.js` called `removeElementFromEndOfArray` that takes an array as its only argument and removes the last element. Your function should return the entire array, and it **should not** mutate the array.
263+
**TODO**: Define a function in `arrays.js` called `removeElementFromEndOfArray` that takes an array as its only argument and removes the last element. Your function should return the array without the last element, and it **should not** mutate the original array.
264264

265265
### From the Middle of an Array
266266

test/arrays-test.js

+31-17
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ describe('arrays', () => {
1717
})
1818

1919
describe('addElementToBeginningOfArray(array, element)', () => {
20-
it('adds an `element` to the beginning of an `array`', () => {
20+
it('adds an element to the beginning of an array', () => {
2121
expect(addElementToBeginningOfArray([1], 'foo')).to.eql(['foo', 1])
2222
})
2323

24-
it('does not alter `array`', () => {
24+
it('does not alter the original array', () => {
2525
const array = [1]
2626

2727
addElementToBeginningOfArray(array, 'foo')
@@ -31,11 +31,11 @@ describe('arrays', () => {
3131
})
3232

3333
describe('destructivelyAddElementToBeginningOfArray(array, element)', () => {
34-
it('adds an `element` to the beginning of an `array`', () => {
34+
it('adds an element to the beginning of an array', () => {
3535
expect(destructivelyAddElementToBeginningOfArray([1], 'foo')).to.eql(['foo', 1])
3636
})
3737

38-
it('alters `array`', () => {
38+
it('alters the original array', () => {
3939
const array = [1]
4040

4141
destructivelyAddElementToBeginningOfArray(array, 'foo')
@@ -45,25 +45,25 @@ describe('arrays', () => {
4545
})
4646

4747
describe('addElementToEndOfArray(array, element)', () => {
48-
it('adds an `element` to the end of an `array`', () => {
48+
it('adds an element to the end of an array', () => {
4949
expect(addElementToEndOfArray([1], 'foo')).to.eql([1, 'foo'])
5050
})
5151

52-
it('does not alter `array`', () => {
52+
it('does not alter the original array', () => {
5353
const array = [1]
5454

5555
addElementToEndOfArray(array, 'foo')
5656

57-
expect(array).to.eql(array)
57+
expect(array).to.eql([1])
5858
})
5959
})
6060

6161
describe('destructivelyAddElementToEndOfArray(array, element)', () => {
62-
it('adds an `element` to the end of an `array`', () => {
62+
it('adds an element to the end of an array', () => {
6363
expect(destructivelyAddElementToEndOfArray([1], 'foo')).to.eql([1, 'foo'])
6464
})
6565

66-
it('alters `array`', () => {
66+
it('alters the original array', () => {
6767
const array = [1]
6868

6969
destructivelyAddElementToEndOfArray(array, 'foo')
@@ -73,44 +73,58 @@ describe('arrays', () => {
7373
})
7474

7575
describe('accessElementInArray(array, index)', () => {
76-
it('accesses the element in `array` at the given `index`', () => {
76+
it('accesses the element in array at the given index', () => {
7777
expect(accessElementInArray([1, 2, 3], 2)).to.equal(3)
7878
})
7979
})
8080

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

86-
it('did not make a copy of the array when removing the first element', ()=>{
86+
it('alters the original array', ()=>{
8787
const array = [1, 2, 3];
8888
destructivelyRemoveElementFromBeginningOfArray(array);
8989
expect(array).to.eql([2, 3]);
9090
})
9191
})
9292

9393
describe('removeElementFromBeginningOfArray(array)', () => {
94-
it('removes the first element from the `array`', () => {
94+
it('removes the first element from the array', () => {
9595
expect(removeElementFromBeginningOfArray([1, 2, 3])).to.eql([2, 3])
9696
})
97+
98+
it('does not alter the original array', () => {
99+
const array = [1, 2, 3];
100+
101+
removeElementFromBeginningOfArray(array);
102+
103+
expect(array).to.eql([1, 2, 3]);
104+
})
97105
})
98106

99107
describe('destructivelyRemoveElementFromEndOfArray(array)', () => {
100-
it('returns the `array` with the last element removed', () => {
108+
it('returns the array with the last element removed', () => {
101109
expect(destructivelyRemoveElementFromEndOfArray([1, 2, 3])).to.eql([1, 2])
102110
})
103111

104-
it('did not make a copy of the array when removing the last element', ()=>{
112+
it('alters the original array', ()=>{
105113
const array = [1, 2, 3];
106114
destructivelyRemoveElementFromEndOfArray(array);
107115
expect(array).to.eql([1, 2]);
108116
})
109117
})
110118

111119
describe('removeElementFromEndOfArray(array)', () => {
112-
it('removes the last element from the `array`', () => {
120+
it('removes the last element from the array', () => {
113121
expect(removeElementFromEndOfArray([1, 2, 3])).to.eql([1, 2])
114122
})
123+
124+
it('does not alter the original array', () => {
125+
const array = [1, 2, 3];
126+
removeElementFromEndOfArray(array);
127+
expect(array).to.eql([1, 2, 3]);
128+
})
115129
})
116-
})
130+
})

0 commit comments

Comments
 (0)