Skip to content

Commit b28cc67

Browse files
committed
lint
1 parent 313820d commit b28cc67

File tree

1 file changed

+24
-25
lines changed

1 file changed

+24
-25
lines changed

day4/day4.js

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import fs from 'fs'
22
import path from 'path'
3-
import { fileURLToPath } from 'url';
4-
const __filename = fileURLToPath(import.meta.url);
5-
const __dirname = path.dirname(__filename);
3+
import { fileURLToPath } from 'url'
4+
const __filename = fileURLToPath(import.meta.url)
5+
const __dirname = path.dirname(__filename)
66

7-
8-
function getRawData () {
7+
function getRawData() {
98
try {
109
const data = fs.readFileSync(path.resolve(__dirname, 'data.txt'), 'utf8')
1110
return data
@@ -14,11 +13,10 @@ function getRawData () {
1413
}
1514
}
1615

17-
1816
class Spot {
1917
constructor(number) {
2018
this.marked = false
21-
this.number = parseInt(number)
19+
this.number = Number.parseInt(number)
2220
}
2321
mark() {
2422
this.marked = true
@@ -27,9 +25,9 @@ class Spot {
2725

2826
class BingoBoard {
2927
constructor(rawBoard) {
30-
this.rows = rawBoard.map(row => {
28+
this.rows = rawBoard.map((row) => {
3129
const rowArr = row.trim().split(/\s+/)
32-
return rowArr.map(number => new Spot(number))
30+
return rowArr.map((number) => new Spot(number))
3331
})
3432
}
3533

@@ -45,7 +43,7 @@ class BingoBoard {
4543
isBingo() {
4644
// any horizontal
4745
for (const row of this.rows) {
48-
if (row.every(spot => spot.marked)) return true
46+
if (row.every((spot) => spot.marked)) return true
4947
}
5048
// any vertical
5149
for (let i = 0; i < this.rows[0].length; i++) {
@@ -64,7 +62,7 @@ class BingoBoard {
6462
calcSumOfUnmarked() {
6563
let sumUnmarked = 0
6664
for (const row of this.rows) {
67-
row.forEach(spot => {
65+
row.forEach((spot) => {
6866
if (!spot.marked) {
6967
sumUnmarked += spot.number
7068
}
@@ -74,7 +72,6 @@ class BingoBoard {
7472
}
7573
}
7674

77-
7875
const data = getRawData()
7976
const lines = data.split('\n')
8077

@@ -85,8 +82,8 @@ let rawBoard = []
8582
let boardCollection = []
8683
for (const line of lines) {
8784
if (index === 0) {
88-
callouts = line.split(',').map(callout => parseInt(callout))
89-
} else if (line === '') {
85+
callouts = line.split(',').map((callout) => Number.parseInt(callout))
86+
} else if (line === '') {
9087
rawBoard = []
9188
} else {
9289
rawBoard.push(line)
@@ -100,23 +97,25 @@ for (const line of lines) {
10097
index++
10198
}
10299

103-
function runTheGame () {
100+
function runTheGame() {
104101
let winningScore
105102
callouts.every((callout, index) => {
106103
boardCollection.every((board, boardIndex) => {
107104
board.checkAndMark(callout)
108-
if (index >= 5) {
109-
if (board.isBingo()){
110-
const unmarkedSum = board.calcSumOfUnmarked()
111-
winningScore = callout * unmarkedSum
112-
console.log(`Bingo! Board ${boardIndex} won the game in ${index+1} moves on the called number ${callout}! The unmarked sum was ${unmarkedSum}, for a total score of ${winningScore}`)
113-
return false; // acts like a break statement in an "every"
114-
}
105+
if (index >= 5 && board.isBingo()) {
106+
const unmarkedSum = board.calcSumOfUnmarked()
107+
winningScore = callout * unmarkedSum
108+
console.log(
109+
`Bingo! Board ${boardIndex} won the game in ${
110+
index + 1
111+
} moves on the called number ${callout}! The unmarked sum was ${unmarkedSum}, for a total score of ${winningScore}`
112+
)
113+
return false // acts like a break statement in an "every"
115114
}
116-
return true;
115+
return true
117116
})
118-
if (winningScore) return false;
119-
return true;
117+
if (winningScore) return false
118+
return true
120119
})
121120
return winningScore
122121
}

0 commit comments

Comments
 (0)