Remove lodash chunk, groupBy

(re: #6087)
This commit is contained in:
Bryan Housel
2019-03-27 16:18:41 -04:00
parent 4cc8d796a6
commit 3d80e6505f
15 changed files with 164 additions and 82 deletions
+52 -11
View File
@@ -1,5 +1,5 @@
describe('iD.utilArrayDifference', function() {
it('returns set difference', function() {
describe('iD.utilArray', function() {
it('utilArrayDifference returns difference of two Arrays', function() {
var a = [1, 2, 3];
var b = [4, 3, 2];
expect(iD.utilArrayDifference([], [])).to.eql([]);
@@ -8,10 +8,8 @@ describe('iD.utilArrayDifference', function() {
expect(iD.utilArrayDifference(a, b)).to.have.members([1]);
expect(iD.utilArrayDifference(b, a)).to.have.members([4]);
});
});
describe('iD.utilArrayIntersection', function() {
it('returns set intersection', function() {
it('utilArrayIntersection returns intersection of two Arrays', function() {
var a = [1, 2, 3];
var b = [4, 3, 2];
expect(iD.utilArrayIntersection([], [])).to.eql([]);
@@ -20,10 +18,8 @@ describe('iD.utilArrayIntersection', function() {
expect(iD.utilArrayIntersection(a, b)).to.have.members([2, 3]);
expect(iD.utilArrayIntersection(b, a)).to.have.members([2, 3]);
});
});
describe('iD.utilArrayUnion', function() {
it('returns set union', function() {
it('utilArrayUnion returns union of two Arrays', function() {
var a = [1, 2, 3];
var b = [4, 3, 2];
expect(iD.utilArrayUnion([], [])).to.eql([]);
@@ -32,12 +28,57 @@ describe('iD.utilArrayUnion', function() {
expect(iD.utilArrayUnion(a, b)).to.have.members([1, 2, 3, 4]);
expect(iD.utilArrayUnion(b, a)).to.have.members([1, 2, 3, 4]);
});
});
describe('iD.utilArrayUniq', function() {
it('returns unique values', function() {
it('utilArrayUniq returns unique values in an Array', function() {
var a = [1, 1, 2, 3, 3];
expect(iD.utilArrayUniq([])).to.eql([]);
expect(iD.utilArrayUniq(a)).to.have.members([1, 2, 3]);
});
it('utilArrayChunk returns array split into given sized chunks', function() {
var a = [1, 2, 3, 4, 5, 6, 7];
// bad chunkSizes, just copy whole array into a single chunk
expect(iD.utilArrayChunk(a)).to.eql([[1, 2, 3, 4, 5, 6, 7]]);
expect(iD.utilArrayChunk(a), -1).to.eql([[1, 2, 3, 4, 5, 6, 7]]);
expect(iD.utilArrayChunk(a), 0).to.eql([[1, 2, 3, 4, 5, 6, 7]]);
// good chunkSizes
expect(iD.utilArrayChunk(a, 2)).to.eql([[1, 2], [3, 4], [5, 6], [7]]);
expect(iD.utilArrayChunk(a, 3)).to.eql([[1, 2, 3], [4, 5, 6], [7]]);
expect(iD.utilArrayChunk(a, 4)).to.eql([[1, 2, 3, 4], [5, 6, 7]]);
});
describe('utilArrayGroupBy', function() {
var pets = [
{ type: 'Dog', name: 'Spot' },
{ type: 'Cat', name: 'Tiger' },
{ type: 'Dog', name: 'Rover' },
{ type: 'Cat', name: 'Leo' }
];
it('groups by key property', function() {
var expected = {
'Dog': [{type: 'Dog', name: 'Spot'}, {type: 'Dog', name: 'Rover'}],
'Cat': [{type: 'Cat', name: 'Tiger'}, {type: 'Cat', name: 'Leo'}]
};
expect(iD.utilArrayGroupBy(pets, 'type')).to.eql(expected);
});
it('groups by key function', function() {
var expected = {
3: [{type: 'Cat', name: 'Leo'}],
4: [{type: 'Dog', name: 'Spot'}],
5: [{type: 'Cat', name: 'Tiger'}, {type: 'Dog', name: 'Rover'}]
};
var keyFn = function(item) { return item.name.length; };
expect(iD.utilArrayGroupBy(pets, keyFn)).to.eql(expected);
});
it('undefined key function', function() {
var expected = {
undefined: pets
};
expect(iD.utilArrayGroupBy(pets)).to.eql(expected);
});
});
});