Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save azakordonets/af8bd42bcc86935808e95a5c30b4f58f to your computer and use it in GitHub Desktop.
Save azakordonets/af8bd42bcc86935808e95a5c30b4f58f to your computer and use it in GitHub Desktop.
const split = (str, nmb) => {
return str.split('')
.reduce((arr, rec) => {
console.log(`Arr: ${arr} Rec : ${rec}`)
if (arr[arr.length - 1].length < nmb) {
arr[arr.length - 1] = [...arr[arr.length - 1], rec]
return arr
}
return [...arr, [rec]]
}, [[]])
.map(el => el.join(''))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment