Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const reduceTitle = (title, limit = 20) => {
- const newTitle = [];
- if (title.length > limit) {
- title.split(" ").reduce((acc, cur) => {
- if (acc + cur.length <= limit) {
- newTitle.push(cur);
- }
- return acc + cur.length;
- }, 0);
- return `${newTitle.join(" ")}...`;
- }
- return title;
- };
Add Comment
Please, Sign In to add comment