You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/* Create a function truncate(str, maxlength) that checks the length of the str and, if it exceeds maxlength – replaces the end of str with the ellipsis character "…",
to make its length equal to maxlength.
The result of the function should be the truncated (if needed) string. */
functiontruncate(str,n){
if(str.length>n){
returnstr.slice(0,n-1)+'...'
}else{-1
returnstr
}
}
truncate("What I'd like to tell on this topic is:",20)//= "What I'd like to te…"