Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Regex solution in Clear category for [old] Cut Sentence by SaintDron
"use strict";
function cutSentence(line, length) {
if (length > line.length) return line;
return line.slice(0, length + 1).replace(/\s*\S*$/, '...');
}
var assert = require('assert');
if (!global.is_checking) {
assert.equal(cutSentence("Hi my name is Alex", 8), "Hi my...", "First")
assert.equal(cutSentence("Hi my name is Alex", 4), "Hi...", "Second")
assert.equal(cutSentence("Hi my name is Alex", 20), "Hi my name is Alex", "Third")
console.log("Done! Do you like it? Go Check it!");
}
March 1, 2018
Comments: