From 7960e8d3d853a0d7a42c67650e6590e29c76bbc0 Mon Sep 17 00:00:00 2001 From: SageBinder Date: Sat, 13 Apr 2019 01:32:44 -0700 Subject: [PATCH] Prints the longest word as well as the length of the longest word --- src/background.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/background.js b/src/background.js index c22319d..b9241f6 100644 --- a/src/background.js +++ b/src/background.js @@ -15,12 +15,14 @@ chrome.contextMenus.onClicked.addListener((info) => { let totalLength = 0; let maxLength = 0; + let longestWord = ""; for (let i = 0; i < wordCount; i++) { - const curLength = words[i] - .replace(/[.,?!()<>{}[\]/\\+=~'`|:;]/g, '').length; + const curWord = words[i].replace(/[.,?!()<>{}[\]/\\+=~'`|:;]/g, ''); + const curLength = curWord.length; totalLength += curLength; if (curLength > maxLength) { maxLength = curLength; + longestWord = curWord; } } const avgLength = wordCount === 0 @@ -32,5 +34,5 @@ chrome.contextMenus.onClicked.addListener((info) => { alert(`Word Count: ${wordCount} Character Count: ${charCount} Average Word Length: ${avgLength.toFixed(numAverageDigits)} -Longest Word Length: ${maxLength}`); +Longest Word Length: ${maxLength} ("${longestWord}")`); });