const { Glib, Maps } = require('../../lib'); const parse = (input) => Glib.fromLines(input).reduce((frequencies, string, index) => { if (index === 0) { frequencies = []; for (let i = 0; i < string.length; i++) { frequencies[i] = string[i].characterFrequencies; } } else { for (let i = 0; i < string.length; i++) { frequencies[i] = Maps.add( frequencies[i], string[i].characterFrequencies, ); } } return frequencies; }, null); module.exports = { '1': (input) => parse(input) .glib.map((i) => i.glibEntries.reduce( ([maxChar, maxCount], [char, count]) => maxCount > count ? [maxChar, maxCount] : [char, count], ['!', -Infinity], ), ) .map(([char]) => char).string, '2': (input) => parse(input) .glib.map((i) => i.glibEntries.reduce( ([minChar, minCount], [char, count]) => count < minCount ? [char, count] : [minChar, minCount], ['!', Infinity], ), ) .map(([char]) => char).string, };