From a1323ecfd94339ac11cf7c926e8d5e5167fe8c3c Mon Sep 17 00:00:00 2001 From: James Langley Date: Mon, 31 Aug 2020 14:38:18 +0100 Subject: [PATCH] Show only 'word' for 1 word found (#13) --- src/Main.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Main.js b/src/Main.js index 2fb8e9e..7380aaf 100644 --- a/src/Main.js +++ b/src/Main.js @@ -76,6 +76,10 @@ const Main = () => { clearResults() } + function countFoundWords(fw) { + return Object.entries(fw).reduce((acc, [wordLen, words]) => acc + words.length, 0) + } + function handlePaths(paths) { const results = paths .map(path => ({ @@ -308,7 +312,7 @@ const Main = () => { processing ? 'Finding words...' : _.isEmpty(foundWords) ? 'Fill in grid to begin' - : `${Object.entries(foundWords).reduce((acc, [wordLen, words]) => acc + words.length, 0)} Words Found` + : `${countFoundWords(foundWords)} Word${countFoundWords(foundWords) > 1 ? 's' : ''} Found` } }