const fs = require('fs') let data = JSON.parse(fs.readFileSync('./Day 2/data.json')) let invalid = [] data.forEach(element => { 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)