Guest User

Untitled

a guest
Dec 15th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.31 KB | None | 0 0
  1. const reduceTitle = (title, limit = 20) => {
  2. const newTitle = [];
  3. if (title.length > limit) {
  4. title.split(" ").reduce((acc, cur) => {
  5. if (acc + cur.length <= limit) {
  6. newTitle.push(cur);
  7. }
  8. return acc + cur.length;
  9. }, 0);
  10. return `${newTitle.join(" ")}...`;
  11. }
  12. return title;
  13. };
Add Comment
Please, Sign In to add comment