Parcourir la source

stuck on day 2 :(

karl.hudgell il y a 4 ans
Parent
commit
ec59e4d6d1
2 fichiers modifiés avec 16 ajouts et 9 suppressions
  1. 5 0
      Day 2/dataTest.json
  2. 11 9
      Day 2/part2.js

+ 5 - 0
Day 2/dataTest.json

@@ -0,0 +1,5 @@
+[
+    ["1-3 a", " abcde"  ],
+    ["1-3 b"," cdefg"  ],
+    ["2-9 c"," ccccccccc"  ]
+  ]

+ 11 - 9
Day 2/part2.js

@@ -12,16 +12,18 @@ async function main() {
         let info2 = info[0].split('-')
         let stringSplit = element[1].split('')
 
-        if (stringSplit[info2[0]] === info[1]) {
-            if (stringSplit[info2[1]] === info[1]) {
-                console.log('correct')
-            } else {
-                invalid.push(element)
-            }
-        } else {
+        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
+                if (stringSplit[info2[0]] !== info[1]) {
+                    invalid.push(element)
+                } else
+                    if (stringSplit[info2[0]] !== info[1] && stringSplit[info2[1]] === info[1]) {
+                        invalid.push(element)
+                    }
     }
     let answer = data.length - invalid.length
     console.log(answer)