refactor: getInput function

This commit is contained in:
2023-12-02 00:04:23 +01:00
parent 65251c07ad
commit 29a5fa493b
3 changed files with 9 additions and 2 deletions

View File

@@ -1,8 +1,10 @@
// REALLY UNCLEAN CODE BUT IT WORKS
import getInput from "../../util/getInput.ts"
const regex = /\D/g
const array: Array<number> = []
const file = (await (Bun.file('./src/days/1/input.txt')).text()).split('\n')
const file = (await getInput(1)).split('\n')
file.forEach((line) => {
let arr = Array.from(line.replace(regex, '')).map(Number)
console.log(`${arr} ${line}`)

View File

@@ -1,8 +1,10 @@
import getInput from "../../util/getInput.ts"
// REALLY UNCLEAN CODE BUT IT WORKS
const regex = /\D/g
const array: Array<number> = []
let file = await (Bun.file('./src/days/1/input.txt')).text()
let file = await getInput(1)
file = file.replaceAll("twone", "21")
file = file.replaceAll("sevenine", "79")
file = file.replaceAll("oneight", "18")

View File

@@ -0,0 +1,3 @@
export default async function getInput(day: number) {
return await (Bun.file(`./src/days/${day}/input.txt`)).text()
}