1 function limitWordsByCharCount(inputString, wordLimit, charLimit) { 2 // Split the input string into an array of words 3 const words = inputString.split(' '); 4 5 // Initialize variables for the word count and total character count 6 let wordCount = 0; 7 let charCount = 0; 8 let result = []; 9 10 // Iterate over the words 11 for (let word of words) { 12 // If adding this word doesn't exceed the character limit, add it to the result 13 if (charCount + word.length + (result.length > 0 ? 1 : 0) <= charLimit && wordCount < wordLimit) { 14 result.push(word); 15 charCount += word.length + (result.length > 1 ? 1 : 0); // Add space between words if not the first word 16 wordCount++; 17 } else { 18 break; // Stop if we've reached the word limit or character limit 19 } 20 } 21 22 // Join the result array into a string and return it 23 return result.join(' '); 24 }
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.