Skip to content

Commit 9e63219

Browse files
feat(2018 day-12): plant generation rules parser
1 parent 9547d26 commit 9e63219

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

2018/day-10/helpers.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ const parseLine = (input) => {
4444
}
4545

4646
module.exports = {
47+
listToProps: _listToProps,
4748
loadInput,
4849
parseLine
4950
}

2018/day-12/helpers.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const { listToProps } = require('../day-10/helpers')
2+
3+
/**
4+
* Parses a line from the input into structured data
5+
* @param {String} input Line from input stream
6+
* @returns Structured object with patterns and states
7+
*/
8+
const parseLine = (input) => {
9+
return input.split(' => ').reduce((acc, curr, idx) => listToProps(acc, curr, idx, ['id', 'generate']), {})
10+
}
11+
12+
module.exports = {
13+
parseLine
14+
}

2018/day-12/helpers.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ const {
77
describe('--- Day 12: Subterranean Sustainability ---', () => {
88
describe('Helpers:', () => {
99
describe('parseLine(input)', () => {
10-
it.skip('converts a line of the input into structured object', () => {
10+
it('converts a line of the input into structured object', () => {
1111
const test = `..#.. => #`
1212
const expected = {
1313
id: '..#..',
14-
value: '#'
14+
generate: '#'
1515
}
1616
const actual = parseLine(test)
1717
expect(actual).to.deep.equal(expected)

0 commit comments

Comments
 (0)