June 8th, 2024
What's missing in this code?
// Shorten to X lines
// const str = 'To be better\nTo grow\nTo impact';
// console.log(shorten({ str, limit: 1 })); // To be better
// console.log(shorten({ str, limit: 2 }));
// To be better\nTo grow
function shorten({ str, limit })
return str
.split(/
/)
.reduce(
(lines, line) =>
lines.length < limit ?
: lines,
[]
)
.
('\n');
}
Type or select from these options