1234567891011121314151617181920212223242526272829303132 |
- 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;
- }
- 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 count = await find_occurences(element[1], info[1])
- if (count >= info2[0]) {
- if (count <= info2[1]) {
- // console.log('valid')
- } else {
- invalid.push(element)
- }
- } else {
- invalid.push(element)
- }
- // console.log('valid')
- }
- let answer = data.length - invalid.length
- console.log(answer)
- }
- main()
|