Skip to content
This repository has been archived by the owner on Apr 16, 2023. It is now read-only.

Commit

Permalink
feat: simplify odometer result
Browse files Browse the repository at this point in the history
  • Loading branch information
noomorph committed Sep 10, 2021
1 parent 81459fa commit 2bca539
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 3 deletions.
4 changes: 4 additions & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx --no-install commitlint --edit "$1"
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npm run precommit
4 changes: 4 additions & 0 deletions .husky/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npm run prepush
6 changes: 5 additions & 1 deletion src/odometer/Odometer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export class Odometer<Context = unknown> {
public getDifference(
aSet: Intermediate<Context, Replacement<Context>>[],
bSet: Intermediate<Context, Replacement<Context>>[],
): OdometerStats<Context> {
): OdometerStats<Context> | null {
let minimalDistance = Number.POSITIVE_INFINITY;
let aBest: Intermediate<Context, Replacement<Context>> | null = null;
let bBest: Intermediate<Context, Replacement<Context>> | null = null;
Expand All @@ -29,6 +29,10 @@ export class Odometer<Context = unknown> {
}
}

if (aBest == null || bBest == null) {
return null;
}

return {
a: aBest,
b: bBest,
Expand Down
4 changes: 2 additions & 2 deletions src/odometer/OdometerStats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Replacement } from '../multireplacer';
import { Intermediate } from '../utils';

export type OdometerStats<T> = {
a: Intermediate<T, Replacement<T>> | null;
b: Intermediate<T, Replacement<T>> | null;
a: Intermediate<T, Replacement<T>>;
b: Intermediate<T, Replacement<T>>;
distance: number;
};

0 comments on commit 2bca539

Please sign in to comment.