4
How to divide a texto
with or more than 20,000 characters in equal parts and each part containing 5000 characters? (Nodejs)
I have that function:
textBreak = (data) => {
const characterCounter = data.text.length;
const pagesCounter = data.numpages;
var text = data.text;
var math = Math.round(characterCounter / pagesCounter) + 3000;
var index = 0;
var array = [];
while (index < characterCounter) {
array.push(text.substr(math, Math.min(index + math, text.length)));
index += math;
}
console.log('textBreak: sucess');
return { array, pagesCounter, characterCounter, math }
}
module.exports = textBreak;
What you’ve done so far? Edith the question and add a [mcve] showing how you tried to solve the problem so we can give you guidance on what you have already done.
– Augusto Vasques
@Augustovasques ready
– Dominik
But you want to break into 5000 fixed or as per data.numpages?
– Daniel Mendes
Yes, fixed. This function n ta good, I think I don’t even need the numpages, I was just making a calculation to get an idea.
– Dominik