Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for [old] Cut Sentence by Sim0000
"use strict";
function cutSentence(line, length) {
if(line.length <= length) return line;
if(line[length] == ' ') length++;
let s = line.substring(0, length);
let n = s.lastIndexOf(' ');
return s.substring(0, n) + '...';
}
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!");
}
July 14, 2017