7 lines
487 B
JavaScript
7 lines
487 B
JavaScript
|
var input = require("fs").readFileSync("input.txt").toString().replace(/\r/g, "");
|
||
|
var groups = input.split("\n").reduce((a, b)=>{b.split("").forEach((x, i)=>{if(!a[i]){a[i] = [];} a[i].push(x);}); return a;}, []);
|
||
|
var freqs = groups.map((g)=>(g.reduce((a, b)=>{if(!a[b]){a[b] = 0;}; a[b]++; return a;}, {})));
|
||
|
var largest = freqs.map((f)=>(Object.keys(f).map((l)=>[l, f[l]]))).map((f)=>(f.sort((a, b)=>(a[1] - b[1])))).map((a)=>(a[0][0]));
|
||
|
var key = largest.join("");
|
||
|
console.log(key);
|