en.javascript.info/1-js/4-data-structures/3-string/3-truncate/solution.md
Ilya Kantor 2b874a73be ok
2016-03-09 00:16:22 +03:00

11 lines
345 B
Markdown

The maximal length must be `maxlength`, so we need to cut it a little shorter, to give space for the ellipsis.
Note that there is actually a single unicode character for an ellipsis. That's not three dots.
```js run
function truncate(str, maxlength) {
return (str.length > maxlength) ?
str.slice(0, maxlength - 1) + '…' : str;
}
```