Skip to content

Commit 098e385

Browse files
feat(2018 day-07): parse log file to structured data
1 parent 0ece5ca commit 098e385

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

2018/day-07/solution.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const { loadInput } = require('./helpers')
2+
const {
3+
parseEntry,
4+
sortInstructions
5+
} = require('./steps')
6+
7+
const init = (data) => {
8+
data = data.map(parseEntry)
9+
const answer = sortInstructions(parseEntry).map((el) => el.id).join('')
10+
console.log(`-- Part 1 --`)
11+
console.log(`Answer: ${answer}`)
12+
console.log(`-- Part 2 --`)
13+
// console.log(`Answer: ${answer2}`)
14+
}
15+
16+
loadInput(init)

2018/day-07/steps.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@
66
* @returns {Object} structured data
77
*/
88
const parseEntry = (line, idx, arr) => {
9-
let entry = {}
10-
return entry
9+
let data = line.split(' ')
10+
return {
11+
id: data[7],
12+
dep: data[1]
13+
}
1114
}
1215

1316
/**

2018/day-07/steps.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ Step F must be finished before step E can begin.`.split('\n')
1616
describe('--- Day 7: The Sum of Its Parts ---', () => {
1717
describe('Part 1:', () => {
1818
describe('parseEntry', () => {
19-
it.skip('Parses a line of the log to create a structured data object representing the entry', () => {
19+
it('Parses a line of the log to create a structured data object representing the entry', () => {
2020
const test = testData[4]
2121
const expected = {
2222
id: 'E',
2323
dep: 'B'
2424
}
2525
const actual = parseEntry(test)
26-
expect(actual).to.equal(expected)
26+
expect(actual).to.deep.equal(expected)
2727
})
2828
})
2929
describe('sortInstructions()', () => {

0 commit comments

Comments
 (0)