JSFiddle - React, Tailwind, and code Playground
by emilcieslar
JavaScript
function TrimSentence(source, length) {
var result;
debugger
result = source.substr(0, length);
var re = /\w$/;
if (re.test(result)) {
var matches = result.match(/\W\w+$/);
result = source.substr(0, matches.index);
}
return result;
}
const result = TrimSentence('Whatever sentence is this, it is goig to be trimmed.\n\nAnd this is another sentence', 15);
alert(result);