Created
December 4, 2020 14:17
-
-
Save kimagure44/d3e72ab12887101891e5c1a9591cead0 to your computer and use it in GitHub Desktop.
Advent of code (2020) - CODE 4 - 1
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 result = []; | |
let t = []; | |
let validPassport = 0; | |
const passportStruct = ['byr', 'iyr', 'eyr', 'hgt', 'hcl', 'ecl', 'pid']; // cid opcional | |
const entries = (await(await fetch('https://adventofcode.com/2020/day/4/input')).text()).split('\n').map(item => { | |
if (item) { | |
t.push(item); | |
} else { | |
item = t.slice(); | |
t = []; | |
return item; | |
} | |
}).filter(item => item).map(item => item.map(el => el.split(' ')).flat()); | |
entries.forEach(item => { | |
if (item.length === 8) { | |
validPassport++; | |
} | |
if (item.length === 7) { | |
const isValid = !item.some(el => el.includes('cid')); | |
if (isValid) { | |
validPassport++; | |
} | |
} | |
}); | |
const startTime = performance.now(); | |
const endTime = performance.now(); | |
console.log(`Pasaportes válidos: ${validPassport}`, `${parseFloat(endTime - startTime).toFixed(4)} ms`); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment