12345678910111213141516171819202122232425262728 |
- const fs = require('fs')
- let data = JSON.parse(fs.readFileSync('./Day 2/data.json'))
- let invalid = []
- function find_occurences(str, char_to_count) {
- return str.split(char_to_count).length - 1;
- }
- data.forEach(element => {
- let info = element[0].split(' ')
- let info2 = info[0].split('-')
- let count = find_occurences(element[1], info[1])
- if (count >= info2[0]) {
- if (count <= info2[1]) {
- console.log(element)
- } else {
- invalid.push(element)
- }
- } else {
- invalid.push(element)
- }
- console.log(element)
- });
- let answer = data.length - invalid.length
- console.log('Valid ' + answer)
|