Truncate a String 算法基础:截断字符串


Tell us what’s happening:

Your code so far

function truncateString(str, num) {
  // Clear out that junk in your trunk
  if(str.length > num){
    return str.slice(0, num) + "..."
  return str;


truncateString("A-tisket a-tasket A green and yellow basket", 8);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36.


理解了 ,已经 不用看了 ! 不知怎么回事 删不了!