|
2 | 2 | const expect = require('chai').expect
|
3 | 3 | const {
|
4 | 4 | dynamicSort,
|
| 5 | + dynamicSortMultiple, |
5 | 6 | loadInput,
|
6 | 7 | parseLog,
|
7 | 8 | parseLogEntry
|
@@ -46,6 +47,42 @@ describe('--- Day 4: Repose Record ---', () => {
|
46 | 47 | expect(actual[2].key).to.equal(expected.last)
|
47 | 48 | })
|
48 | 49 | })
|
| 50 | + |
| 51 | + describe('dynamicSortMultiple()', () => { |
| 52 | + it('sorts an array of objects based on the values in multiple specified keys', () => { |
| 53 | + const test = [ |
| 54 | + { key1: 'a', key2: 4 }, |
| 55 | + { key1: 'z', key2: 3 }, |
| 56 | + { key1: 'z', key2: 1 }, |
| 57 | + { key1: 'm', key3: 2 } |
| 58 | + ] |
| 59 | + const expected = { |
| 60 | + first: 'a', |
| 61 | + last: 'z' |
| 62 | + } |
| 63 | + const actual = test.sort(dynamicSortMultiple('key1', 'key2')) |
| 64 | + expect(actual[0].key1).to.equal(expected.first) |
| 65 | + expect(actual[3].key1).to.equal(expected.last) |
| 66 | + expect(actual[3].key2).to.equal(3) |
| 67 | + }) |
| 68 | + it('prioritizes based on the order of the arguments', () => { |
| 69 | + const test = [ |
| 70 | + { key1: 'a', key2: 4 }, |
| 71 | + { key1: 'z', key2: 3 }, |
| 72 | + { key1: 'z', key2: 1 }, |
| 73 | + { key1: 'm', key2: 2 } |
| 74 | + ] |
| 75 | + const expected = { |
| 76 | + first: 'z', |
| 77 | + last: 'a' |
| 78 | + } |
| 79 | + const actual = test.sort(dynamicSortMultiple('key2', 'key1')) |
| 80 | + expect(actual[0].key1).to.equal(expected.first) |
| 81 | + expect(actual[0].key2).to.equal(1) |
| 82 | + expect(actual[3].key1).to.equal(expected.last) |
| 83 | + }) |
| 84 | + }) |
| 85 | + |
49 | 86 | describe('loadInput()', () => {
|
50 | 87 | it.skip('loads the contents of the input file into a string', () => {
|
51 | 88 | expect(loadInput()).to.equal(testInput)
|
|
0 commit comments