Skip to content

Instantly share code, notes, and snippets.

@cranzy
Created November 28, 2018 17:17
Show Gist options
  • Save cranzy/b20374925fcd92775ce24439dc65c48e to your computer and use it in GitHub Desktop.
Save cranzy/b20374925fcd92775ce24439dc65c48e to your computer and use it in GitHub Desktop.
const limitRecipeTitle = (title, limit=17) => {
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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment