79136148

Date: 2024-10-29 07:17:30
Score: 1
Natty:
Report link

Thanks for the other solutions

I make a new one:

function extractString(sperator, str, limit = -1) {
  const parts = str.split(sperator);

  if (parts.length <= limit) {
    return parts;
  }

  return [
    ...parts.slice(0, limit - 1),
    parts.slice(limit - 1, parts.length).join(';'),
  ];
}

const str = 'name;price;content ; content 2 ; content3';

console.log(extractString(';', str, 3));
Reasons:
  • Blacklisted phrase (0.5): Thanks
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: Will