Мое решение:
export const shorten = (s, n) => {
let newStr = ''
newStr = s.slice(0, n);
if (newStr.length == n) {
newStr = newStr + '...';
}
return newStr;
}
Но появляется ошибка
Сами строки
import { shorten } from './functions.js';
const longString = 'this string is quite long, especially for its age.'
const shortString = 'a short one'
const mediumString = 'this string is too long to fit our ad'
console.log(shorten(longString, 20));
console.log(shorten(shortString, 20));
console.log(shorten(mediumString, 21));
console.log(shorten(longString, 60));