Skip to content

Commit 3f5ea2d

Browse files
committed
Complete AboutArray.js
1 parent f960d7c commit 3f5ea2d

File tree

1 file changed

+30
-30
lines changed

1 file changed

+30
-30
lines changed

koans/AboutArrays.js

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@ describe("About Arrays", function() {
33
//We shall contemplate truth by testing reality, via spec expectations.
44
it("should create arrays", function() {
55
var emptyArray = [];
6-
expect(typeof(emptyArray)).toBe(FILL_ME_IN); //A mistake? - http:javascript.crockford.com/remedial.html
7-
expect(emptyArray.length).toBe(FILL_ME_IN);
6+
expect(typeof(emptyArray)).toBe('object'); //A mistake? - http:javascript.crockford.com/remedial.html
7+
expect(emptyArray.length).toBe(0);
88

99
var multiTypeArray = [0, 1, "two", function () { return 3; }, {value1: 4, value2: 5}, [6, 7]];
10-
expect(multiTypeArray[0]).toBe(FILL_ME_IN);
11-
expect(multiTypeArray[2]).toBe(FILL_ME_IN);
12-
expect(multiTypeArray[3]()).toBe(FILL_ME_IN);
13-
expect(multiTypeArray[4].value1).toBe(FILL_ME_IN);
14-
expect(multiTypeArray[4]["value2"]).toBe(FILL_ME_IN);
15-
expect(multiTypeArray[5][0]).toBe(FILL_ME_IN);
10+
expect(multiTypeArray[0]).toBe(0);
11+
expect(multiTypeArray[2]).toBe('two');
12+
expect(multiTypeArray[3]()).toBe(3);
13+
expect(multiTypeArray[4].value1).toBe(4);
14+
expect(multiTypeArray[4]["value2"]).toBe(5);
15+
expect(multiTypeArray[5][0]).toBe(6);
1616
});
1717

1818
it("should understand array literals", function () {
@@ -23,36 +23,36 @@ describe("About Arrays", function() {
2323
expect(array).toEqual([1]);
2424

2525
array[1] = 2;
26-
expect(array).toEqual([1, FILL_ME_IN]);
26+
expect(array).toEqual([1, 2]);
2727

2828
array.push(3);
29-
expect(array).toEqual(FILL_ME_IN);
29+
expect(array).toEqual([1, 2, 3]);
3030
});
3131

3232
it("should understand array length", function () {
3333
var fourNumberArray = [1, 2, 3, 4];
3434

35-
expect(fourNumberArray.length).toBe(FILL_ME_IN);
35+
expect(fourNumberArray.length).toBe(4);
3636
fourNumberArray.push(5, 6);
37-
expect(fourNumberArray.length).toBe(FILL_ME_IN);
37+
expect(fourNumberArray.length).toBe(6);
3838

3939
var tenEmptyElementArray = new Array(10);
40-
expect(tenEmptyElementArray.length).toBe(FILL_ME_IN);
40+
expect(tenEmptyElementArray.length).toBe(10);
4141

4242
tenEmptyElementArray.length = 5;
43-
expect(tenEmptyElementArray.length).toBe(FILL_ME_IN);
43+
expect(tenEmptyElementArray.length).toBe(5);
4444
});
4545

4646
it("should slice arrays", function () {
4747
var array = ["peanut", "butter", "and", "jelly"];
4848

49-
expect(array.slice(0, 1)).toEqual(FILL_ME_IN);
50-
expect(array.slice(0, 2)).toEqual(FILL_ME_IN);
51-
expect(array.slice(2, 2)).toEqual(FILL_ME_IN);
52-
expect(array.slice(2, 20)).toEqual(FILL_ME_IN);
53-
expect(array.slice(3, 0)).toEqual(FILL_ME_IN);
54-
expect(array.slice(3, 100)).toEqual(FILL_ME_IN);
55-
expect(array.slice(5, 1)).toEqual(FILL_ME_IN);
49+
expect(array.slice(0, 1)).toEqual(['peanut']);
50+
expect(array.slice(0, 2)).toEqual(['peanut', 'butter']);
51+
expect(array.slice(2, 2)).toEqual([]);
52+
expect(array.slice(2, 20)).toEqual(['and', 'jelly']);
53+
expect(array.slice(3, 0)).toEqual([]);
54+
expect(array.slice(3, 100)).toEqual(['jelly']);
55+
expect(array.slice(5, 1)).toEqual([]);
5656
});
5757

5858
it("should know array references", function () {
@@ -62,36 +62,36 @@ describe("About Arrays", function() {
6262
refArray[1] = "changed in function";
6363
}
6464
passedByReference(array);
65-
expect(array[1]).toBe(FILL_ME_IN);
65+
expect(array[1]).toBe('changed in function');
6666

6767
var assignedArray = array;
6868
assignedArray[5] = "changed in assignedArray";
69-
expect(array[5]).toBe(FILL_ME_IN);
69+
expect(array[5]).toBe('changed in assignedArray');
7070

7171
var copyOfArray = array.slice();
7272
copyOfArray[3] = "changed in copyOfArray";
73-
expect(array[3]).toBe(FILL_ME_IN);
73+
expect(array[3]).toBe('three');
7474
});
7575

7676
it("should push and pop", function () {
7777
var array = [1, 2];
7878
array.push(3);
7979

80-
expect(array).toEqual(FILL_ME_IN);
80+
expect(array).toEqual([1, 2, 3]);
8181

8282
var poppedValue = array.pop();
83-
expect(poppedValue).toBe(FILL_ME_IN);
84-
expect(array).toEqual(FILL_ME_IN);
83+
expect(poppedValue).toBe(3);
84+
expect(array).toEqual([1, 2]);
8585
});
8686

8787
it("should know about shifting arrays", function () {
8888
var array = [1, 2];
8989

9090
array.unshift(3);
91-
expect(array).toEqual(FILL_ME_IN);
91+
expect(array).toEqual([3, 1, 2]);
9292

9393
var shiftedValue = array.shift();
94-
expect(shiftedValue).toEqual(FILL_ME_IN);
95-
expect(array).toEqual(FILL_ME_IN);
94+
expect(shiftedValue).toEqual(3);
95+
expect(array).toEqual([1, 2]);
9696
});
9797
});

0 commit comments

Comments
 (0)