Skip to content

Commit

Permalink
style(trunk): format the codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewMamdouh committed Aug 28, 2024
1 parent b0a9118 commit 9441dae
Show file tree
Hide file tree
Showing 121 changed files with 1,116 additions and 612 deletions.
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
docs
21 changes: 18 additions & 3 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
{
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
"root": true,
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:prettier/recommended"
],
"plugins": [
"@typescript-eslint",
"jest",
"simple-import-sort",
"unused-imports"
],
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint", "jest"],
"root": true
"rules": {
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": "error",
"unused-imports/no-unused-imports": "error",
"simple-import-sort/exports": "error"
}
}
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
docs
5 changes: 3 additions & 2 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"trailingComma": "es5",
"tabWidth": 4,
"semi": false,
"singleQuote": true
"semi": true,
"singleQuote": true,
"endOfLine": "crlf"
}
8 changes: 4 additions & 4 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { JestConfigWithTsJest, pathsToModuleNameMapper } from 'ts-jest'
import { compilerOptions } from './tsconfig.json'
import { JestConfigWithTsJest, pathsToModuleNameMapper } from 'ts-jest';
import { compilerOptions } from './tsconfig.json';

const jestConfig: JestConfigWithTsJest = {
preset: 'ts-jest/presets/default-esm',
Expand All @@ -9,6 +9,6 @@ const jestConfig: JestConfigWithTsJest = {
roots: ['<rootDir>'],
modulePaths: [compilerOptions.baseUrl],
moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths),
}
};

export default jestConfig
export default jestConfig;
23 changes: 19 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,41 @@
"type": "module",
"scripts": {
"test": "jest",
"doc": "typedoc --entryPointStrategy expand ./src --exclude \"./src/**/*+(test).ts\" --excludeReferences",
"lint": "eslint .",
"format": "prettier . --write"
"doc": "typedoc",
"trunk:check": "trunk check --all",
"trunk:fix": "trunk check --all --fix",
"trunk:format": "trunk fmt",
"type:check": "tsc --project tsconfig.json"
},
"devDependencies": {
"@trunkio/launcher": "^1.3.1",
"@types/jest": "^29.5.11",
"@types/node": "^20.10.8",
"@typescript-eslint/eslint-plugin": "^6.18.1",
"@typescript-eslint/parser": "^6.18.1",
"@yarnpkg/sdks": "^3.1.0",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"eslint-import-resolver-typescript": "^3.6.3",
"eslint-plugin-jest": "^28.2.0",
"eslint-plugin-prettier": "^5.2.1",
"eslint-plugin-simple-import-sort": "^12.1.1",
"eslint-plugin-unused-imports": "^4.1.3",
"jest": "^29.7.0",
"prettier": "^3.2.5",
"ts-jest": "^29.1.1",
"typedoc": "^0.25.7"
"typedoc": "^0.25.13",
"typedoc-plugin-rename-defaults": "^0.7.0",
"typedoc-theme-hierarchy": "^4.1.2"
},
"dependencies": {
"ts-node": "^10.9.2",
"typescript": "^5.3.3"
},
"resolutions": {
"@babel/traverse": "7.23.2",
"braces": "3.0.3",
"micromatch": "4.0.8"
},
"packageManager": "[email protected]"
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { angryProfessor } from '@ProblemSolving/Algorithms/Implementation'
import { angryProfessor } from '@ProblemSolving/Algorithms/Implementation';

test('should return whether the class is cancelled or not', () => {
expect(angryProfessor(3, [-1, -3, 4, 2])).toBe('YES')
})
expect(angryProfessor(3, [-1, -3, 4, 2])).toBe('YES');
});
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
/**
* Determines if the class is cancelled.
* @author Andrew Mamdouh <[email protected]>
* A Discrete Mathematics professor has a class of students.
* Frustrated with their lack of discipline, the professor decides to cancel class if fewer than some number of students are present when class starts.
* Arrival times go from on time `arrivalTime <= 0` to arrived late `arrivalTime > 0`.
*
* Given the arrival time of each student and a threshold number of attendees, determine if the class is cancelled.
*
* @param {number} k - The threshold number of students
* @param {number[]} a - The arrival times of the students
* @returns {"YES" | "NO"} Whether the class is cancelled or not.
* @example
* ```ts
* const result = angryProfessor(3, [-1, -3, 4, 2]);
* console.log(result); // "YES"
* ```
* @author Andrew Mamdouh <[email protected]>
*/
const angryProfessor = (k: number, a: number[]): string => {
const students = a.filter((time) => time <= 0).length
return students < k ? 'YES' : 'NO'
}
const students = a.filter((time) => time <= 0).length;
return students < k ? 'YES' : 'NO';
};

export default angryProfessor
export default angryProfessor;
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { appendAndDelete } from '@ProblemSolving/Algorithms/Implementation'
import { appendAndDelete } from '@ProblemSolving/Algorithms/Implementation';

test('should return "Yes" or "No"', () => {
expect(appendAndDelete('hackerhappy', 'hackerrank', 9)).toBe('Yes')
})
expect(appendAndDelete('hackerhappy', 'hackerrank', 9)).toBe('Yes');
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getLongestCommonSubStr } from '@Helpers'
import { getLongestCommonSubStr } from '@Helpers';
/**
* Determines whether you can convert (s) to (t) by performing exactly (k) of operations
* @author Andrew Mamdouh <[email protected]>
Expand All @@ -8,14 +8,14 @@ import { getLongestCommonSubStr } from '@Helpers'
* @returns {"Yes" | "No"} Whether this can be performed or not
*/
const appendAndDelete = (s: string, t: string, k: number): 'Yes' | 'No' => {
let longestCommonStr = getLongestCommonSubStr(s, t)
if (s.indexOf(longestCommonStr) !== 0) longestCommonStr = ''
const maxOpsNum = s.length + t.length
let longestCommonStr = getLongestCommonSubStr(s, t);
if (s.indexOf(longestCommonStr) !== 0) longestCommonStr = '';
const maxOpsNum = s.length + t.length;
return (maxOpsNum - longestCommonStr.length * 2 <= k &&
(maxOpsNum - longestCommonStr.length * 2) % 2 === k % 2) ||
maxOpsNum <= k
? 'Yes'
: 'No'
}
: 'No';
};

export default appendAndDelete
export default appendAndDelete;
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { countApplesAndOranges } from '@ProblemSolving/Algorithms/Implementation'
import { countApplesAndOranges } from '@ProblemSolving/Algorithms/Implementation';

test("should return the number of apples and oranges that fall on Sam's house", () => {
expect(countApplesAndOranges(7, 11, 5, 15, [-2, 2, 1], [5, -6])).toEqual([
1, 1,
])
})
]);
});
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const countApplesAndOranges = (
(acc, cur) => (acc += b + cur >= s && b + cur <= t ? 1 : 0),
0
),
]
}
];
};

export default countApplesAndOranges
export default countApplesAndOranges;
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { beautifulDays } from '@ProblemSolving/Algorithms/Implementation'
import { beautifulDays } from '@ProblemSolving/Algorithms/Implementation';

test('should return the number of beautiful days', () => {
expect(beautifulDays(20, 23, 6)).toBe(2)
})
expect(beautifulDays(20, 23, 6)).toBe(2);
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { reverseNum } from '@Helpers'
import { reverseNum } from '@Helpers';
/**
* Determines the number of days in the range that are beautiful.
* Beautiful numbers are defined as numbers where |i - reverse(i)| is evenly divisible by k.
Expand All @@ -9,9 +9,9 @@ import { reverseNum } from '@Helpers'
* @returns {number} The number of beautiful days in the range
*/
const beautifulDays = (i: number, j: number, k: number): number => {
let count = 0
let count = 0;
for (let l = i; l <= j; l++)
if (Math.abs(l - reverseNum(l)) % k === 0) count++
return count
}
export default beautifulDays
if (Math.abs(l - reverseNum(l)) % k === 0) count++;
return count;
};
export default beautifulDays;
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getTotalX } from '@ProblemSolving/Algorithms/Implementation'
import { getTotalX } from '@ProblemSolving/Algorithms/Implementation';

test('should return the number of integers that are between the sets', () => {
expect(getTotalX([2, 4], [16, 32, 96])).toBe(3)
})
expect(getTotalX([2, 4], [16, 32, 96])).toBe(3);
});
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,25 @@
*/
const getTotalX = (a: number[], b: number[]): number => {
let count = 0,
isValid: boolean
isValid: boolean;
for (let i = a.at(-1); typeof i === 'number' && i <= b[0]; i++) {
isValid = true
isValid = true;
for (let j = 0; j < a.length; j++) {
if (i % a[j] !== 0) {
isValid = false
break
isValid = false;
break;
}
}
if (!isValid) continue
if (!isValid) continue;
for (let j = 0; j < b.length; j++) {
if (b[j] % i !== 0) {
isValid = false
break
isValid = false;
break;
}
}
if (isValid) count++
if (isValid) count++;
}
return count
}
return count;
};

export default getTotalX
export default getTotalX;
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { bonAppetit } from '@ProblemSolving/Algorithms/Implementation'
import { bonAppetit } from '@ProblemSolving/Algorithms/Implementation';

test('should log the overcharged amount', () => {
console.log = jest.fn()
bonAppetit([3, 10, 2, 9], 1, 12)
expect(console.log).toHaveBeenCalledWith(5)
})
console.log = jest.fn();
bonAppetit([3, 10, 2, 9], 1, 12);
expect(console.log).toHaveBeenCalledWith(5);
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
*/
const bonAppetit = (bill: number[], k: number, b: number): void => {
const annaBill =
bill.reduce((acc, cur, idx) => (idx === k ? acc : acc + cur)) / 2
console.log(b === annaBill ? 'Bon Appetit' : b - annaBill)
}
bill.reduce((acc, cur, idx) => (idx === k ? acc : acc + cur)) / 2;
console.log(b === annaBill ? 'Bon Appetit' : b - annaBill);
};

export default bonAppetit
export default bonAppetit;
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { breakingRecords } from '@ProblemSolving/Algorithms/Implementation'
import { breakingRecords } from '@ProblemSolving/Algorithms/Implementation';

test('should return the numbers representing the times most points records and least points records have been broken', () => {
expect(breakingRecords([10, 5, 20, 20, 4, 5, 2, 25, 1])).toEqual([2, 4])
})
expect(breakingRecords([10, 5, 20, 20, 4, 5, 2, 25, 1])).toEqual([2, 4]);
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@
* @returns {[number, number]} The array contains the numbers representing the times records have been broken
*/
const breakingRecords = (scores: number[]): [number, number] => {
const minMax = Array(2).fill(scores[0])
const minMax = Array(2).fill(scores[0]);
return scores.reduce(
(acc, cur) => {
if (cur > minMax[1]) {
minMax[1] = cur
acc[0]++
minMax[1] = cur;
acc[0]++;
} else if (cur < minMax[0]) {
minMax[0] = cur
acc[1]++
minMax[0] = cur;
acc[1]++;
}
return acc
return acc;
},
[0, 0]
)
}
);
};

export default breakingRecords
export default breakingRecords;
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { catAndMouse } from '@ProblemSolving/Algorithms/Implementation'
import { catAndMouse } from '@ProblemSolving/Algorithms/Implementation';

test('should return Either "Cat A", "Cat B", or "Mouse C"', () => {
expect(catAndMouse(1, 2, 3)).toBe('Cat B')
})
expect(catAndMouse(1, 2, 3)).toBe('Cat B');
});
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ const catAndMouse = (
y: number,
z: number
): 'Cat A' | 'Cat B' | 'Mouse C' => {
const catADistanceDiff = Math.abs(x - z)
const catBDistanceDiff = Math.abs(y - z)
const catADistanceDiff = Math.abs(x - z);
const catBDistanceDiff = Math.abs(y - z);
return catBDistanceDiff > catADistanceDiff
? 'Cat A'
: catADistanceDiff > catBDistanceDiff
? 'Cat B'
: 'Mouse C'
}
: 'Mouse C';
};

export default catAndMouse
export default catAndMouse;
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { chocolateFeast } from '@ProblemSolving/Algorithms/Implementation'
import { chocolateFeast } from '@ProblemSolving/Algorithms/Implementation';

test('should return the number of chocolates Bobby can eat', () => {
expect(chocolateFeast(10, 2, 5)).toBe(6)
})
expect(chocolateFeast(10, 2, 5)).toBe(6);
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
*/
const chocolateFeast = (n: number, c: number, m: number): number => {
let barsCount = Math.floor(n / c),
wrappersCount = Math.floor(n / c)
wrappersCount = Math.floor(n / c);
while (wrappersCount >= m) {
wrappersCount = wrappersCount - m + 1
barsCount += 1
wrappersCount = wrappersCount - m + 1;
barsCount += 1;
}
return barsCount
}
return barsCount;
};

export default chocolateFeast
export default chocolateFeast;
Loading

0 comments on commit 9441dae

Please sign in to comment.