Skip to content

Add Prettier #100

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.github
.nyc_output
node_modules
coverage
pnpm-lock.yaml
CODE_OF_CONDUCT.md
LICENSE
Empty file added .prettierrc
Empty file.
14 changes: 11 additions & 3 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@ import js from "@eslint/js";
import globals from "globals";
import tseslint from "typescript-eslint";
import { defineConfig } from "eslint/config";

import eslintConfigPrettier from "eslint-config-prettier/flat";

export default defineConfig([
{ files: ["**/*.{js,mjs,cjs,ts,mts,cts}"], plugins: { js }, extends: ["js/recommended"] },
{ files: ["**/*.{js,mjs,cjs,ts,mts,cts}"], languageOptions: { globals: globals.browser } },
{
files: ["**/*.{js,mjs,cjs,ts,mts,cts}"],
plugins: { js },
extends: ["js/recommended"],
},
{
files: ["**/*.{js,mjs,cjs,ts,mts,cts}"],
languageOptions: { globals: globals.browser },
},
tseslint.configs.recommended,
eslintConfigPrettier,
]);
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"clean": "rm -rf .nyc_output coverage dist",
"test": "nyc mocha 'src/**/*.test.ts' --require=tsx",
"lint": "eslint 'src/**/*.ts'",
"prettier": "prettier --write .",
"coverage": "nyc report --reporter html && open coverage/index.html",
"coverage:check": "nyc check-coverage --lines 90 --branches 80 --statements 90"
},
Expand All @@ -18,9 +19,11 @@
"@types/sinon": "^17.0.4",
"chai": "^5.2.1",
"eslint": "^9.31.0",
"eslint-config-prettier": "^10.1.5",
"globals": "^16.3.0",
"mocha": "^11.7.1",
"nyc": "^17.1.0",
"prettier": "3.6.2",
"sinon": "^21.0.0",
"tsx": "^4.20.3",
"typescript": "^5.8.3",
Expand Down
23 changes: 23 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/algorithms/dynamic-programming/fibonacci.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from 'chai';
import fibonacci from './fibonacci.ts';
import { expect } from "chai";
import fibonacci from "./fibonacci.ts";

describe("fibonacci", function () {
const tests = [
Expand Down
6 changes: 3 additions & 3 deletions src/algorithms/dynamic-programming/grid-traveller.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from 'chai';
import gridTraveller from './grid-traveller.ts';
import { expect } from "chai";
import gridTraveller from "./grid-traveller.ts";

describe('gridTraveller', () => {
describe("gridTraveller", () => {
const tests = [
{ rows: 0, columns: 0, expected: 0 },
{ rows: 0, columns: 1, expected: 0 },
Expand Down
6 changes: 5 additions & 1 deletion src/algorithms/dynamic-programming/grid-traveller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@
* @param buffer the object used for memoisation
* @returns the total number of ways to travel on a N by M grid
*/
export default function gridTraveller(rows: number, columns: number, buffer: object = {}): number {
export default function gridTraveller(
rows: number,
columns: number,
buffer: object = {},
): number {
const key = getKey(rows, columns);
if (key in buffer) return buffer[key];
if (rows <= 0 || columns <= 0) return 0;
Expand Down
4 changes: 2 additions & 2 deletions src/algorithms/dynamic-programming/sum/can-sum.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from 'chai';
import canSum from './can-sum.ts';
import { expect } from "chai";
import canSum from "./can-sum.ts";

describe("canSum", function () {
const tests = [
Expand Down
6 changes: 5 additions & 1 deletion src/algorithms/dynamic-programming/sum/can-sum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@
* @param buffer the object used for memoisation
* @returns true if the target sun can be constructed
*/
export default function canSum(targetSum: number, numbers: number[], buffer: object = {}): boolean {
export default function canSum(
targetSum: number,
numbers: number[],
buffer: object = {},
): boolean {
if (targetSum in buffer) return buffer[targetSum];
if (targetSum === 0) return true;
if (targetSum < 0) return false;
Expand Down
4 changes: 2 additions & 2 deletions src/algorithms/dynamic-programming/sum/how-sum.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from 'chai';
import howSum from './how-sum.ts';
import { expect } from "chai";
import howSum from "./how-sum.ts";

describe("howSum", function () {
const tests = [
Expand Down
4 changes: 2 additions & 2 deletions src/algorithms/dynamic-programming/sum/shortest-sum.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from 'chai';
import shortestSum from './shortest-sum.ts';
import { expect } from "chai";
import shortestSum from "./shortest-sum.ts";

describe("shortestSum", function () {
const tests = [
Expand Down
12 changes: 6 additions & 6 deletions src/algorithms/matrices.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from 'chai';
import { sum, sumDiagonal, sumAntiDiagonal, sumFrame } from './matrices.js';
import { expect } from "chai";
import { sum, sumDiagonal, sumAntiDiagonal, sumFrame } from "./matrices.js";

describe("Matrix Operations", function () {
const matrix = [
Expand All @@ -9,19 +9,19 @@ describe("Matrix Operations", function () {
[6, 8, 2, 3],
];

it('sum', () => {
it("sum", () => {
expect(sum(matrix)).equal(73);
});

it('sumDiagonal', () => {
it("sumDiagonal", () => {
expect(sumDiagonal(matrix)).equal(21);
});

it('sumAntiDiagonal', () => {
it("sumAntiDiagonal", () => {
expect(sumAntiDiagonal(matrix)).equal(19);
});

it('sumFrame', () => {
it("sumFrame", () => {
expect(sumFrame(matrix)).equal(49);
});
});
26 changes: 15 additions & 11 deletions src/algorithms/search.test.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
import { expect } from 'chai';
import { linearSearch, binarySearch } from '@src/algorithms/search.ts';
import { expect } from "chai";
import { linearSearch, binarySearch } from "@src/algorithms/search.ts";

describe('Search', () => {
const unsortedSequence = [11, 3, 10, 9, 1, 23, 12, 7, 113, 39, 2, 948, 5, 82, 49, 33];
const sortedSequence = [1, 2, 3, 5, 7, 9, 10, 11, 12, 23, 33, 39, 49, 82, 113, 948];
describe("Search", () => {
const unsortedSequence = [
11, 3, 10, 9, 1, 23, 12, 7, 113, 39, 2, 948, 5, 82, 49, 33,
];
const sortedSequence = [
1, 2, 3, 5, 7, 9, 10, 11, 12, 23, 33, 39, 49, 82, 113, 948,
];

describe('Linear Search', () => {
it('should find 11', () => {
describe("Linear Search", () => {
it("should find 11", () => {
expect(linearSearch(11, unsortedSequence)).equal(true);
});

it('should not find 0', () => {
it("should not find 0", () => {
expect(linearSearch(0, unsortedSequence)).equal(false);
});
});

describe('Binary Search', () => {
it('should find 11', () => {
describe("Binary Search", () => {
it("should find 11", () => {
expect(binarySearch(11, sortedSequence)).equal(true);
});

it('should not find 0', () => {
it("should not find 0", () => {
expect(binarySearch(0, sortedSequence)).equal(false);
});
});
Expand Down
6 changes: 3 additions & 3 deletions src/algorithms/sorting/merge-sort.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from 'chai';
import mergeSort from '@src/algorithms/sorting/merge-sort.ts';
import SortingOrder from '@src/util/SortingOrder.ts';
import { expect } from "chai";
import mergeSort from "@src/algorithms/sorting/merge-sort.ts";
import SortingOrder from "@src/util/SortingOrder.ts";

describe("mergeSort", function () {
const tests = [
Expand Down
17 changes: 13 additions & 4 deletions src/algorithms/sorting/merge-sort.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import SortingOrder from '../../util/SortingOrder';
import SortingOrder from "../../util/SortingOrder";

interface Split {
left: Array<number>;
Expand Down Expand Up @@ -31,7 +31,11 @@ function whoGoesFirst(x: number, y: number, order: SortingOrder): Operand {
return Operand.Left;
}

function merge(left: Array<number>, right: Array<number>, order: SortingOrder): Array<number> {
function merge(
left: Array<number>,
right: Array<number>,
order: SortingOrder,
): Array<number> {
let leftIndex = 0;
let rightIndex = 0;

Expand All @@ -40,7 +44,9 @@ function merge(left: Array<number>, right: Array<number>, order: SortingOrder):
// while the left index or the right index are not out of bound
while (leftIndex < left.length || rightIndex < right.length) {
if (leftIndex < left.length && rightIndex < right.length) {
if (whoGoesFirst(left[leftIndex], right[rightIndex], order) === Operand.Left) {
if (
whoGoesFirst(left[leftIndex], right[rightIndex], order) === Operand.Left
) {
sortedArray.push(left[leftIndex]);
leftIndex += 1;
} else {
Expand All @@ -67,7 +73,10 @@ function merge(left: Array<number>, right: Array<number>, order: SortingOrder):
* @param input the array of numbers to sort.
* @param order specify the order of sorting: ascending or descending.
*/
export default function mergeSort(input: Array<number> | null, order: SortingOrder): Array<number> | null {
export default function mergeSort(
input: Array<number> | null,
order: SortingOrder,
): Array<number> | null {
if (!Array.isArray(input) || input.length <= 1) return input;

const splitInput: Split = split(input);
Expand Down
Loading