-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.js
More file actions
26 lines (20 loc) · 755 Bytes
/
utils.js
File metadata and controls
26 lines (20 loc) · 755 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
const fs = require("fs");
const getInput = (directory, filename = "/input.txt") => {
return fs.readFileSync(directory + filename, "utf8");
};
const getInputArray = (directory, filename = "/input.txt") => {
const input = getInput(directory, filename);
return input.split("\n");
};
const print = (input, space = 2, asText = false) => {
if (asText) {
console.log("\n");
console.log(input.map((cols) => cols.join("")).join("\n"));
console.log("\n");
} else {
console.log(JSON.stringify(input, null, space));
}
};
const arrayEquals = (a, b) => JSON.stringify(a) === JSON.stringify(b);
const deepClone = (input) => JSON.parse(JSON.stringify(input));
module.exports = { getInputArray, getInput, print, arrayEquals, deepClone };