Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
shahata committed Sep 28, 2024
1 parent 68838df commit b35e18e
Show file tree
Hide file tree
Showing 12 changed files with 26 additions and 18 deletions.
8 changes: 8 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,12 @@ export default [
...typescript.configs.recommended,
prettier,
{ languageOptions: { globals: globals.browser } },
{
rules: {
'prefer-const': ['error', { destructuring: 'all' }],
'prefer-template': 'error',
'array-callback-return': 'error',
'no-useless-assignment': 'error',
},
},
];
2 changes: 1 addition & 1 deletion src/2015/day07.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function makeCircuit(input) {
x.match(/^(?:(\w+) )?(?:(AND|OR|NOT|LSHIFT|RSHIFT) (\w+) )?-> (\w+)$/),
)
.map(x => ({
op: ops[x[2] + ''],
op: ops[`${x[2]}`],
p1: getter(x[1]),
p2: getter(x[3]),
result: x[4],
Expand Down
2 changes: 1 addition & 1 deletion src/2015/day10.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
function transform(s) {
return s
.match(/(.)\1*/g)
.map(x => x.length + '' + x[0])
.map(x => `${x.length}${x[0]}`)
.join('');
}

Expand Down
8 changes: 4 additions & 4 deletions src/2016/day17.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import md5 from '../utils/md5.js';

function getNeighbors(point, [U, D, L, R]) {
return [
U && { x: point.x, y: point.y - 1, path: point.path + 'U' },
D && { x: point.x, y: point.y + 1, path: point.path + 'D' },
L && { x: point.x - 1, y: point.y, path: point.path + 'L' },
R && { x: point.x + 1, y: point.y, path: point.path + 'R' },
U && { x: point.x, y: point.y - 1, path: `${point.path}U` },
D && { x: point.x, y: point.y + 1, path: `${point.path}D` },
L && { x: point.x - 1, y: point.y, path: `${point.path}L` },
R && { x: point.x + 1, y: point.y, path: `${point.path}R` },
].filter(p => p && p.x >= 0 && p.y >= 0 && p.x <= 3 && p.y <= 3);
}

Expand Down
2 changes: 1 addition & 1 deletion src/2018/day12.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function transform(current, transformations, memo, i) {
return recall(current, memo, i);
}
current.start -= 5;
current.state = '.....' + current.state + '.....';
current.state = `.....${current.state}.....`;
const next = { start: current.start, state: '..' };
for (let i = 0; i < current.state.length - 5; i++) {
if (transformations[current.state.slice(i, i + 5)] === '#') {
Expand Down
4 changes: 2 additions & 2 deletions src/2018/day15.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ function fight(input, elfBoost = 0) {

export function part1(input) {
const { i, units } = fight(input);
return i * units.reduce((sum, u) => (sum += u.hit), 0);
return i * units.reduce((sum, u) => sum + u.hit, 0);
}

export function part2(input) {
Expand All @@ -96,5 +96,5 @@ export function part2(input) {
({ i, units } = fight(input, elfBoost));
elfBoost++;
} while (elfCount !== count(units, 'E'));
return i * units.reduce((sum, u) => (sum += u.hit), 0);
return i * units.reduce((sum, u) => sum + u.hit, 0);
}
2 changes: 1 addition & 1 deletion src/2019/day17.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export function part1(input) {
export function part2(input) {
const map = createMap(input);
const route = findRoute(map).join(',');
const [, A, B, C] = (route + ',').match(
const [, A, B, C] = `${route},`.match(
/^(.{1,20}),(?:\1,)*(.{1,20}),(?:\1,|\2,)*(.{1,20}),(?:\1,|\2,|\3,)*$/,
);
const main = route
Expand Down
2 changes: 1 addition & 1 deletion src/2020/day11.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function neighbors(seats, current, far) {
function life(input, count, far) {
let seats = input.split('\n').map(x => x.split(''));
let occupied = 0;
let prev = 0;
let prev;
do {
seats = seats.map((line, y) =>
line.map((seat, x) => {
Expand Down
4 changes: 2 additions & 2 deletions src/2020/day17.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ function neighbors(key) {

export function part1(input, dimensions = 3) {
const map = new Map();
input.split('\n').map((line, y) => {
line.split('').map((char, x) => {
input.split('\n').forEach((line, y) => {
line.split('').forEach((char, x) => {
const coordinates = new Array(dimensions - 2).fill(0);
map.set([x, y, ...coordinates].join(','), char === '#');
});
Expand Down
2 changes: 1 addition & 1 deletion src/2022/day12.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function part2(input) {
const str = input.replace('S', 'a');
let min = Infinity;
for (const { index } of str.matchAll(/a/g)) {
const result = part1(str.slice(0, index) + 'S' + str.slice(index + 1));
const result = part1(`${str.slice(0, index)}S${str.slice(index + 1)}`);
min = result < min ? result : min;
}
return min;
Expand Down
2 changes: 1 addition & 1 deletion src/2022/day21.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function parse(input) {
/^([a-z]+): ([a-z]+) (.) ([a-z]+)$/,
);
return { variable, param1, operator, param2 };
}
} else return undefined;
})
.reduce((obj, x) => ({ ...obj, [x.variable]: x }), {});
}
Expand Down
6 changes: 3 additions & 3 deletions src/2023/day18.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ export function part1(input) {

export function part2(input) {
const lines = input.split('\n').map(line => {
let [direction, count, color] = line.split(' ');
count = parseInt(color.slice(2, -2), 16);
direction = 'RDLU'.at(color.slice(-2, -1));
const [, , color] = line.split(' ');
const count = parseInt(color.slice(2, -2), 16);
const direction = 'RDLU'.at(color.slice(-2, -1));
return { direction, count };
});
return solve(lines);
Expand Down

0 comments on commit b35e18e

Please sign in to comment.