Quotes help make search much faster. Example: "Practice Makes Perfect"

Friday, May 12, 2017

FreeCodeCamp Truncate A String Sample Solution



function truncateString(str, num) {
  // Clear out that junk in your trunk
  if(num >= str.length){
    return str;
  }
  if(num > 3){
    return str.substring(0,num-3) + "...";
  } else {
    return str.substring(0,num) + "...";
  }
}

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

No comments:

Post a Comment


This is an example of scrolling text using Javascript.

Popular Posts