Last active
September 28, 2016 22:31
-
-
Save veeracs/4317f46fa14ef6ca5dd740e141841295 to your computer and use it in GitHub Desktop.
Ellipsis
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function ellipsis(str, charLimit) { | |
var result = []; | |
var letters = 0; | |
str.split(' ').forEach(function(word, index) { | |
if (letters < charLimit) {result.push(word)} | |
letters += word.length; | |
}); | |
console.log(result.join(' ') + ' ...'); | |
})("Hero congressman calls out conservatives on racist abortion restrictions", 40); |
endtwist
commented
Sep 28, 2016
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment