Skip to content

Instantly share code, notes, and snippets.

@kimagure44
Created December 7, 2020 14:59
Show Gist options
  • Save kimagure44/bd557ac160774b570a24f9ccd321356d to your computer and use it in GitHub Desktop.
Save kimagure44/bd557ac160774b570a24f9ccd321356d to your computer and use it in GitHub Desktop.
(async () => {
const entries = (await(await fetch('https://adventofcode.com/2020/day/6/input')).text()).split('\n').map(item => item);
const startTime = performance.now();
let arr = [];
let total = [];
entries.forEach(item => {
if (item.length > 0) {
arr.push(Array.from(item).sort((a, b) => a > b ? 1 : -1));
} else {
const totalSet = new Set(arr.flat());
total.push({ arr: totalSet, size: totalSet.size });
arr = [];
}
});
let recuento = 0;
total.forEach(item => {
console.log(item);
recuento += item.size;
});
const endTime = performance.now();
console.log(recuento, `${parseFloat(endTime - startTime).toFixed(4)} ms`);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment