const fs = require('fs') let data = JSON.parse(fs.readFileSync('./Day 2/data.json')) let invalid = [] async function main() { for (let index = 0; index < data.length; index++) { const element = data[index]; let info = element[0].split(' ') let info2 = info[0].split('-') let stringSplit = element[1].split('') if (stringSplit[info2[0]] === info[1] && stringSplit[info2[1]] === info[1]) { invalid.push(element) } else if (stringSplit[info2[0]] !== info[1] && stringSplit[info2[1]] !== info[1]) { invalid.push(element) } else { console.log(element) } } let answer = data.length - invalid.length console.log('Valid ' + answer) } main()