Created
November 28, 2018 17:17
-
-
Save cranzy/b20374925fcd92775ce24439dc65c48e to your computer and use it in GitHub Desktop.
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
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