I wrote my function like this: truncate('Hello world!, 5);
But I want write my function like this: 'Hello world!'.truncate(5);
function truncate(str, num) {
if (str.length <= num) {
return str
}
return str.slice(0, num) + '...'
}
console.log(truncate('Hello world!', 5))