Skip to content

Commit 454eace

Browse files
committed
cleaning up lodash exercise
1 parent c4ab374 commit 454eace

File tree

3 files changed

+8
-46
lines changed

3 files changed

+8
-46
lines changed

lodash_exercise/lodash.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
function chunk(arr,param){
2-
3-
}
4-
51
function drop(){
62

73
}
@@ -42,10 +38,6 @@ function zipObject(){
4238

4339
}
4440

45-
function every(){
46-
47-
}
48-
4941
function includes(){
5042

5143
}

lodash_exercise/lodashSpec.js

Lines changed: 8 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,5 @@
11
var expect = chai.expect
22

3-
describe("#chunk", function(){
4-
it("should break up an array into subarrays", function(){
5-
expect(chunk(['a', 'b', 'c', 'd'], 2)).to.deep.equal([['a', 'b'], ['c', 'd']])
6-
});
7-
it("should leave remaining chunks as subarrays", function(){
8-
expect(chunk(['a', 'b', 'c', 'd'], 3)).to.deep.equal([['a', 'b', 'c'], ['d']])
9-
});
10-
it("returns an array of arrays if the second parameter is greater or equal to the length", function(){
11-
expect(chunk(['a', 'b', 'c', 'd'], 10)).to.deep.equal([['a', 'b', 'c','d']])
12-
});
13-
});
14-
153
describe("#drop", function(){
164
it("should remove the first element of an array when no second parameter is passed", function(){
175
expect(drop([1,2,3])).to.deep.equal([2,3])
@@ -75,7 +63,7 @@ describe("#takeRight", function(){
7563
expect(takeRight([1, 2, 3], 2)).to.deep.equal([2, 3])
7664
});
7765
it("copies the entire array if the second parameter is greater or equal to the length of the array", function(){
78-
expect(takeRight([1, 2, 3], 5)).to.deep.equal([1, 2])
66+
expect(takeRight([1, 2, 3], 5)).to.deep.equal([1, 2,3])
7967
});
8068
it("returns an empty array if the second parameter is 0", function(){
8169
expect(takeRight([1, 2, 3], 0)).to.deep.equal([])
@@ -126,23 +114,7 @@ describe("#zipObject", function(){
126114
expect(zipObject(['a', 'b'], [1, 2])).to.deep.equal({ 'a': 1, 'b': 2 })
127115
});
128116
it("should create keys and values if a value in the first array is specified", function(){
129-
expect(zipObject(['a', 'b','c','d'], [1, 2, 3])).to.deep.equal({a: 1, b: 2, c: 3, d: 10})
130-
});
131-
});
132-
133-
describe("#every", function(){
134-
it("should", function(){
135-
expect(every([true, 1, null, 'yes'], Boolean)).to.equal(false)
136-
137-
var users = [
138-
{ 'user': 'barney', 'age': 36, 'active': false },
139-
{ 'user': 'fred', 'age': 40, 'active': false }
140-
];
141-
142-
expect(every(users, { 'user': 'barney', 'active': false })).to.equal(false)
143-
144-
expect(every(users, ['active', false])).to.equal(true)
145-
expect(every(users, 'active')).to.equal(false)
117+
expect(zipObject(['a', 'b','c','d'], [1, 2, 3])).to.deep.equal({a: 1, b: 2, c: 3, d: undefined})
146118
});
147119
});
148120

@@ -264,15 +236,15 @@ describe("#omitBy", function(){
264236
});
265237
});
266238

267-
describe("#pad", function(){
268-
it("should pad with whitespace if no second parameter is passed in", function(){
269-
expect(pad('abc', 8)).to.equal(' abc ')
239+
describe("#padEnd", function(){
240+
it("should pad with whitespace if no third parameter is passed in", function(){
241+
expect(padEnd('abc', 6)).to.equal('abc ')
270242
});
271243
it("should pad both directions evenly", function(){
272-
expect(pad('abc', 8, '_-')).to.equal('_-abc_-_')
244+
expect(padEnd('abc', 6, '_-')).to.equal('abc_-_')
273245
});
274246
it("should not pad with anything if the length is less than or equal", function(){
275-
expect(pad('abc', 3)).to.equal('abc')
247+
expect(padEnd('abc', 3)).to.equal('abc')
276248
});
277249
});
278250

@@ -303,4 +275,4 @@ describe("#flattenDeep", function(){
303275
it("should flatten a nested array completely", function(){
304276
expect(flattenDeep([1, [2, [3, [4]], 5]])).to.deep.equal([1, 2, 3, 4, 5])
305277
});
306-
});;
278+
});

lodash_exercise/readme.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
For this assignment, you will be re-implementing functions from the popular Lodash library. Examine each of these functions in detail and see how they are used before you try to implement them:
44

5-
- [chunk](https://lodash.com/docs/4.17.4#chunk)
65
- [drop](https://lodash.com/docs/4.17.4#drop)
76
- [fromPairs](https://lodash.com/docs/4.17.4#fromPairs)
87
- [head](https://lodash.com/docs/4.17.4#head)
@@ -13,7 +12,6 @@ For this assignment, you will be re-implementing functions from the popular Loda
1312
- [zip](https://lodash.com/docs/4.17.4#zip)
1413
- [unzip](https://lodash.com/docs/4.17.4#unzip)
1514
- [zipObject](https://lodash.com/docs/4.17.4#zipObject)
16-
- [every](https://lodash.com/docs/4.17.4#every)
1715
- [includes](https://lodash.com/docs/4.17.4#includes)
1816
- [sample](https://lodash.com/docs/4.17.4#sample)
1917
- [flip](https://lodash.com/docs/4.17.4#flip)

0 commit comments

Comments
 (0)