My result comes out correct, but I get the 'exceeded execution timeout of 40 seconds' error.
I have done this:
export const shortenByWords = (s, n) => {
if(s.length > n) {
for(let i = n + 1; i > 0; i++) {
if(s === ' '){
return s.slice(0, i) + '...';
}
}
} else {
return s
}
}