From 2bca539f9f5a40b510861c62a3e9754914ad24e5 Mon Sep 17 00:00:00 2001 From: Yaroslav Serhieiev Date: Fri, 10 Sep 2021 11:25:29 +0300 Subject: [PATCH] feat: simplify odometer result --- .husky/commit-msg | 4 ++++ .husky/pre-commit | 4 ++++ .husky/pre-push | 4 ++++ src/odometer/Odometer.ts | 6 +++++- src/odometer/OdometerStats.ts | 4 ++-- 5 files changed, 19 insertions(+), 3 deletions(-) create mode 100755 .husky/commit-msg create mode 100755 .husky/pre-commit create mode 100755 .husky/pre-push diff --git a/.husky/commit-msg b/.husky/commit-msg new file mode 100755 index 0000000..0bd658f --- /dev/null +++ b/.husky/commit-msg @@ -0,0 +1,4 @@ +#!/bin/sh +. "$(dirname "$0")/_/husky.sh" + +npx --no-install commitlint --edit "$1" diff --git a/.husky/pre-commit b/.husky/pre-commit new file mode 100755 index 0000000..6e9bf51 --- /dev/null +++ b/.husky/pre-commit @@ -0,0 +1,4 @@ +#!/bin/sh +. "$(dirname "$0")/_/husky.sh" + +npm run precommit diff --git a/.husky/pre-push b/.husky/pre-push new file mode 100755 index 0000000..42b62e5 --- /dev/null +++ b/.husky/pre-push @@ -0,0 +1,4 @@ +#!/bin/sh +. "$(dirname "$0")/_/husky.sh" + +npm run prepush diff --git a/src/odometer/Odometer.ts b/src/odometer/Odometer.ts index e6302c0..17e9c88 100644 --- a/src/odometer/Odometer.ts +++ b/src/odometer/Odometer.ts @@ -8,7 +8,7 @@ export class Odometer { public getDifference( aSet: Intermediate>[], bSet: Intermediate>[], - ): OdometerStats { + ): OdometerStats | null { let minimalDistance = Number.POSITIVE_INFINITY; let aBest: Intermediate> | null = null; let bBest: Intermediate> | null = null; @@ -29,6 +29,10 @@ export class Odometer { } } + if (aBest == null || bBest == null) { + return null; + } + return { a: aBest, b: bBest, diff --git a/src/odometer/OdometerStats.ts b/src/odometer/OdometerStats.ts index 6f66636..8b349ea 100644 --- a/src/odometer/OdometerStats.ts +++ b/src/odometer/OdometerStats.ts @@ -2,7 +2,7 @@ import { Replacement } from '../multireplacer'; import { Intermediate } from '../utils'; export type OdometerStats = { - a: Intermediate> | null; - b: Intermediate> | null; + a: Intermediate>; + b: Intermediate>; distance: number; };