From bbfdc923fba92fb7c138b93f01e5503ebeb78be1 Mon Sep 17 00:00:00 2001 From: James Grugett Date: Tue, 10 May 2022 10:27:52 -0400 Subject: [PATCH] Fix word scores, broken by an extra long word --- common/recommended-contracts.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/common/recommended-contracts.ts b/common/recommended-contracts.ts index be50c5cd..2de75293 100644 --- a/common/recommended-contracts.ts +++ b/common/recommended-contracts.ts @@ -69,9 +69,14 @@ const contractToText = (contract: Contract) => { return `${creatorUsername} ${question} ${tags.join(' ')} ${description}` } +const MAX_CHARS_IN_WORD = 100 + const getWordsCount = (text: string) => { const normalizedText = text.replace(/[^a-zA-Z]/g, ' ').toLowerCase() - const words = normalizedText.split(' ').filter((word) => word) + const words = normalizedText + .split(' ') + .filter((word) => word) + .filter((word) => word.length <= MAX_CHARS_IN_WORD) const counts: { [word: string]: number } = {} for (const word of words) {