Created
December 8, 2020 00:19
-
-
Save kimagure44/1d4492eb3cf92e80f158a834c1bfb2c9 to your computer and use it in GitHub Desktop.
Advent of code (2020) - CODE 6 - 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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 { | |
let arrSet = new Set(arr.flat()); | |
let obj = {}; | |
arr.forEach(val => { | |
val.forEach(iItem => { | |
if (arrSet.has(iItem)) { | |
obj[iItem] = obj[iItem] + 1 || 1; | |
} | |
}) | |
}); | |
const saveArr = Object.values(obj).filter(i => i === arr.length).length; | |
console.log(saveArr); | |
total.push(saveArr); | |
arr = []; | |
} | |
}); | |
const recuento = total.reduce((o, n) => o + n, 0); | |
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