function shortenText(text, maxLength) {
  if (text.length > maxLength) {
    return text.substring(0, maxLength) + '...';
  } else {
    return text;
  }
}
const title = "This is a very long title that needs to be shortened";
const shortenedTitle = shortenText(title, 20);
console.log(shortenedTitle); // Output: "This is a very long tit..."

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.