Skip to content

Commit

Permalink
Merge pull request #21 from ieedan/new-blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
ieedan authored Nov 20, 2024
2 parents f332adc + fa1fe47 commit 77830e1
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 66 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ jobs:
- name: Install dependencies
run: pnpm install

- name: Check Types
run: pnpm check:types

- name: Lint
run: pnpm check

Expand Down
84 changes: 18 additions & 66 deletions jsrepo-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@
"category": "types",
"tests": true,
"subdirectory": false,
"files": [
"result.ts",
"result.test.ts"
],
"files": ["result.ts", "result.test.ts"],
"localDependencies": [],
"dependencies": [],
"devDependencies": []
Expand All @@ -27,10 +24,7 @@
"category": "utilities",
"tests": true,
"subdirectory": false,
"files": [
"array-sum.ts",
"array-sum.test.ts"
],
"files": ["array-sum.ts", "array-sum.test.ts"],
"localDependencies": [],
"dependencies": [],
"devDependencies": []
Expand All @@ -41,10 +35,7 @@
"category": "utilities",
"tests": true,
"subdirectory": false,
"files": [
"array-to-map.ts",
"array-to-map.test.ts"
],
"files": ["array-to-map.ts", "array-to-map.test.ts"],
"localDependencies": [],
"dependencies": [],
"devDependencies": []
Expand All @@ -55,10 +46,7 @@
"category": "utilities",
"tests": true,
"subdirectory": false,
"files": [
"dispatcher.ts",
"dispatcher.test.ts"
],
"files": ["dispatcher.ts", "dispatcher.test.ts"],
"localDependencies": [],
"dependencies": [],
"devDependencies": []
Expand All @@ -69,14 +57,8 @@
"category": "utilities",
"tests": true,
"subdirectory": false,
"files": [
"ipv4-address.ts",
"ipv4-address.test.ts"
],
"localDependencies": [
"types/result",
"utilities/is-number"
],
"files": ["ipv4-address.ts", "ipv4-address.test.ts"],
"localDependencies": ["types/result", "utilities/is-number"],
"dependencies": [],
"devDependencies": []
},
Expand All @@ -86,10 +68,7 @@
"category": "utilities",
"tests": true,
"subdirectory": false,
"files": [
"is-number.ts",
"is-number.test.ts"
],
"files": ["is-number.ts", "is-number.test.ts"],
"localDependencies": [],
"dependencies": [],
"devDependencies": []
Expand All @@ -100,13 +79,8 @@
"category": "utilities",
"tests": true,
"subdirectory": false,
"files": [
"lines.ts",
"lines.test.ts"
],
"localDependencies": [
"utilities/pad"
],
"files": ["lines.ts", "lines.test.ts"],
"localDependencies": ["utilities/pad"],
"dependencies": [],
"devDependencies": []
},
Expand All @@ -116,10 +90,7 @@
"category": "utilities",
"tests": true,
"subdirectory": false,
"files": [
"map-to-array.ts",
"map-to-array.test.ts"
],
"files": ["map-to-array.ts", "map-to-array.test.ts"],
"localDependencies": [],
"dependencies": [],
"devDependencies": []
Expand All @@ -130,13 +101,8 @@
"category": "utilities",
"tests": true,
"subdirectory": false,
"files": [
"pad.ts",
"pad.test.ts"
],
"localDependencies": [
"utilities/strip-ansi"
],
"files": ["pad.ts", "pad.test.ts"],
"localDependencies": ["utilities/strip-ansi"],
"dependencies": [],
"devDependencies": []
},
Expand All @@ -146,10 +112,7 @@
"category": "utilities",
"tests": true,
"subdirectory": false,
"files": [
"sleep.ts",
"sleep.test.ts"
],
"files": ["sleep.ts", "sleep.test.ts"],
"localDependencies": [],
"dependencies": [],
"devDependencies": []
Expand All @@ -160,10 +123,7 @@
"category": "utilities",
"tests": true,
"subdirectory": false,
"files": [
"stopwatch.ts",
"stopwatch.test.ts"
],
"files": ["stopwatch.ts", "stopwatch.test.ts"],
"localDependencies": [],
"dependencies": [],
"devDependencies": []
Expand All @@ -174,14 +134,9 @@
"category": "utilities",
"tests": true,
"subdirectory": false,
"files": [
"strip-ansi.ts",
"strip-ansi.test.ts"
],
"files": ["strip-ansi.ts", "strip-ansi.test.ts"],
"localDependencies": [],
"dependencies": [
"ansi-regex@^6.1.0"
],
"dependencies": ["ansi-regex@^6.1.0"],
"devDependencies": []
},
{
Expand All @@ -190,14 +145,11 @@
"category": "utilities",
"tests": true,
"subdirectory": false,
"files": [
"truncate.ts",
"truncate.test.ts"
],
"files": ["truncate.ts", "truncate.test.ts"],
"localDependencies": [],
"dependencies": [],
"devDependencies": []
}
]
}
]
]
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"format": "biome format --write",
"lint": "biome lint --write",
"check": "biome check",
"check:types": "tsc --noEmit",
"build": "jsrepo build --dirs src",
"docs:generate": "typedoc"
},
Expand Down
10 changes: 10 additions & 0 deletions src/utilities/math/fractions.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { describe, expect, it } from 'vitest';
import * as math from '.';

describe('simplify', () => {
it('simplifies fractions correctly', () => {
expect(math.fractions.simplify(1920, 1080)).toStrictEqual([16, 9]);
// like in usage
expect(math.fractions.simplify(1920, 1080).join(':')).toBe('16:9');
});
});
20 changes: 20 additions & 0 deletions src/utilities/math/fractions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { gcf } from './gcf';

/** Simplifies the fraction
*
* @param numerator
* @param denominator
* @returns
*
* ## Usage
* ```ts
* simplify(1920, 1080).join(":"); // 16:9
* ```
*/
const simplify = (numerator: number, denominator: number): [number, number] => {
const factor = gcf(numerator, denominator);

return [numerator / factor, denominator / factor];
};

export { simplify };
20 changes: 20 additions & 0 deletions src/utilities/math/gcf.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { describe, expect, it } from 'vitest';
import * as math from '.';

describe('gcf', () => {
it('solves GCF correctly', () => {
expect(math.gcf(1920, 1080)).toBe(120);
expect(math.gcf(-1920, 1080)).toBe(120);
expect(math.gcf(1080, 1920)).toBe(120);
expect(math.gcf(2, 2)).toBe(2);
});
});

describe('gcd', () => {
it('solves GCD correctly', () => {
expect(math.gcd(1920, 1080)).toBe(120);
expect(math.gcd(-1920, 1080)).toBe(120);
expect(math.gcd(1080, 1920)).toBe(120);
expect(math.gcd(2, 2)).toBe(2);
});
});
43 changes: 43 additions & 0 deletions src/utilities/math/gcf.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/** Solves the GCF (Greatest Common Factor) using the **Euclidean Algorithm**
*
* @param a
* @param b
* @returns
*
* ## Usage
* ```ts
* gcf(1920, 1080); // 120
* gcf(2, 2); // 2
* ```
*/
const gcf = (a: number, b: number): number => {
// if they are negative we really just want the same thing
let num1: number = Math.abs(a);
let num2: number = Math.abs(b);

while (num1 !== num2) {
if (num1 > num2) {
num1 -= num2;
} else {
num2 -= num1;
}
}

return num1;
};

/** Solves the GCD (Greatest Common Divisor) using the **Euclidean Algorithm** (Alternate alias of `gcf`)
*
* @param a
* @param b
* @returns
*
* ## Usage
* ```ts
* gcd(1920, 1080); // 120
* gcd(2, 2); // 2
* ```
*/
const gcd = gcf;

export { gcf, gcd };
4 changes: 4 additions & 0 deletions src/utilities/math/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import * as fractions from './fractions';
import { gcd, gcf } from './gcf';

export { gcf, gcd, fractions };

0 comments on commit 77830e1

Please sign in to comment.