<filename>2-resources/BLOG/Data-Structures/Simple-Algorithm/Truncate-String.js<gh_stars>0
//Truncate a string (first argument) if it is longer than the given maximum string length (second argument). Return the truncated string with a ... ending.
function truncateString(str, num){
    if(str.length > num) {
        return str.slice(0,num) + "...";
    }
    else {
return str;
    }
}
console.log(truncateString("<NAME> picked a peck of pickled peppers",11))
console.log(truncateString("A-tisket a-tasket A green and yellow basket","A-tisket a-tasket A green and yellow basket".length,))
console.log(truncateString("A-tisket a-tasket A green and yellow basket", "A-tisket a-tasket A green and yellow basket".length + 2))

