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


#1

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.


#2

这个题的参考答案不管用,而且说得似是而非! 我这个答案能过关