woops mixed up 'and' and 'or'

This commit is contained in:
mtrx 2024-12-04 23:18:44 +01:00
parent ccf3e827a9
commit 1478c47666

View file

@ -14,7 +14,7 @@ class DayTwo implements Solvable {
while (j < levels.length) { while (j < levels.length) {
// is unsafe if ascent / descend bigger than 3 or smaller than 1 // is unsafe if ascent / descend bigger than 3 or smaller than 1
const diff = Math.abs(levels[i] - levels[j]) const diff = Math.abs(levels[i] - levels[j])
if (diff > 3 && diff < 1) { if (diff > 3 || diff < 1) {
return false return false
} }
// calculate positive or negative gradient // calculate positive or negative gradient
@ -22,10 +22,7 @@ class DayTwo implements Solvable {
gradients.push("ascending") gradients.push("ascending")
} else if (levels[i] > levels[j]) { } else if (levels[i] > levels[j]) {
gradients.push("descending") gradients.push("descending")
} else { } i++
return false
}
i++
j++ j++
} }
// is safe and constant gradient? // is safe and constant gradient?