-
Notifications
You must be signed in to change notification settings - Fork 15
/
input.js
31 lines (28 loc) · 807 Bytes
/
input.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
const path = require('path');
const fs = require('fs');
const input = fs
.readFileSync(path.join(__dirname, 'input.txt'), 'utf8')
.toString()
.trim()
.split('\n')
.map((line) => {
/**
* @example mxmxvkd kfcds sqjhc nhms (contains dairy, fish)
* @example trh fvjkl sbzzf mxmxvkd (contains dairy)
*/
let [ingredients] = line.split(' (contains');
ingredients = ingredients.split(' ');
// let ingredients_lookup = ingredients.reduce((obj, v) => ((obj[v] = true), obj), {});
let [, allergens] = /contains ([\w,\s]+)\)/.exec(line);
allergens = allergens.split(', ');
// let allergens_lookup = allergens.reduce((obj, v) => ((obj[v] = true), obj), {});
return {
ingredients,
// ingredients_lookup,
allergens,
// allergens_lookup,
};
});
module.exports = {
input,
};