Hi, Here is my implementation for task 145.
As expected, I'm getting the output
PS C:\Coding\cdsl> node c:/Coding/cdsl/task145/solution.js
this string is...
a short one
But for some reason when I submit the task I get a failure on:
x The result should end with ... if the original string had to be shortened
Here is my code:
export const shortenByWords = (s, n) => {
var newS = "";
if(s.length <= n) {
newS = s;
} else{
for(var i = n; i > 0; i--) {
if(s.charAt(i) == " " && s.charAt(i - 1) != " ") {
newS = `${s.substring(0, i)}...`;
break;
}
}
}
return newS;
}