Cool, many ways of doing this.
This is what I came up with:
function capitalizeFirstLast(string = "") { const _firstLastWord = word => { if (!word || word.length <= 1) { return word.toUpperCase(); } let len = word.length; const upperAt = i => word.charAt(i).toUpperCase(); return `${upperAt(0)}${word.substr(1, len - 2)}${upperAt(len - 1)}`; }; return string.length ? string .toLowerCase() .split(" ") .map(_firstLastWord) .join(" ") : string; }
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Cool, many ways of doing this.
This is what I came up with: