Forked from [Alain Galvan](http://codepen.io/alaingalvan/)'s Pen [Hueshift](http://codepen.io/alaingalvan/pen/FwpBs/) and [beesandtrees](http://codepen.io/beesandtrees/)'s Pen [Bleeding Madras](http://codepen.io/beesandtrees/pen/MYdmjE/) and [xoihazard](http://codepen.io/xoihazard/)'s Pen [Hexagonal Grid Test](http://codepen.io/xoihazard/pen/yyrgqL/).
Take away: function truncate(string, limit) { if (!string) return; if (string.length < limit) return string; var substring = string.substring(0, limit); var spacePosition = substring.lastIndexOf(' '); if (spacePosition === substring.length) return substring; else return substring.substring(0, spacePosition) + '...'; }