fix: Crash when comparing two long words

This commit is contained in:
Alexander Polynomdivision
2018-10-09 12:48:12 +02:00
parent 3834590c5a
commit 7e27203f74
4 changed files with 5 additions and 54 deletions

View File

@@ -27,7 +27,8 @@ import {
} from "../models/vocab";
import { ReviewType, IReviewMetadata } from "../models/review";
import { levW } from "../algorithms/levenshtein";
//@ts-ignore
import lev from "js-levenshtein";
import {
LEVENSHTEIN_MAX_DISTANCE, MAX_ERROR_THRESHOLD,
REVIEW_HELP_MOD
@@ -213,7 +214,7 @@ const ReviewPageWithRouter = withRouter(
// Map all possible answers to lowercase ( => ignore casing)
const answers = current.answers.map((el) => el.toLowerCase());
// Calculate the distances to all possible answers
const dists = answers.map((el) => levW(input.toLowerCase(), el));
const dists = answers.map((el) => lev(input.toLowerCase(), el));
// Find the lowest distance
const minDist = Math.min(...dists);