DEV Community

Discussion on: JavaScript Katas: Split In Parts

Collapse
nibble profile image
Joseph Mawa

Another possible solution.

function splitInParts(myString, partLength) {
  let ans = "",
    i = 0;
  while (i < myString.length) {
    ans += myString.slice(i, i + partLength) + " ";
    i += partLength;
  }
  return ans.slice(0, -1);
}
Enter fullscreen mode Exit fullscreen mode