Implement the function shorten(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.
So, shorten(‘this string is too long to fit our ad’, 21) returns this string is too lo...
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 shorten = (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.
* */
import { shorten } from './functions.js';
const longString = 'this string is quite long, especially for its age.'
const shortString = 'a short one'
console.log(shorten(longString, 20));
console.log(shorten(shortString, 20));