Implement the function shortenByWords(s, n).

It should accept a string, and a number.
It should return the new string that consists of maximum n characters of the original string.
If you have to cut off some chars, place ... in the end.

You can’t cut in the middle of the word, so the result should include only the full words.
So, shortenByWords(‘this string is too long to fit our ad’, 21) returns this string is too...

This task is part of the Full-Stack JavaScript Course
If you have any issues with it, you can ask for community help below the post
Feel free to help others if you’ve already solved the task

functions.js

export const shortenByWords = (s, n) => {
  return s.slice(0, n);
}

solution.js

/**
 * Implement the function shorten(s, n).
 *
 * It should shorten the string to the first 'n' chars and add '...' if the shortening did happen.
 *
 * Only full words can be included in the result.
 * */

import { shortenByWords } from './functions.js';

const longString = 'this string is quiteeeeeeeeeeeeeee long, especially for its age.'
const shortString = 'a short one'

console.log(shortenByWords(longString, 20));
console.log(shortenByWords(shortString, 20));