part1.js 824 B

1234567891011121314151617181920212223242526272829303132
  1. const fs = require('fs')
  2. let data = JSON.parse(fs.readFileSync('./Day 2/data.json'))
  3. let invalid = []
  4. function find_occurences(str, char_to_count) {
  5. return str.split(char_to_count).length - 1;
  6. }
  7. async function main() {
  8. for (let index = 0; index < data.length; index++) {
  9. const element = data[index];
  10. let info = element[0].split(' ')
  11. let info2 = info[0].split('-')
  12. let count = await find_occurences(element[1], info[1])
  13. if (count >= info2[0]) {
  14. if (count <= info2[1]) {
  15. // console.log('valid')
  16. } else {
  17. invalid.push(element)
  18. }
  19. } else {
  20. invalid.push(element)
  21. }
  22. // console.log('valid')
  23. }
  24. let answer = data.length - invalid.length
  25. console.log(answer)
  26. }
  27. main()