How many chunks?
Take your time, follow the code and check your understanding.
The codeRAG fundamentals
const text = "abcdefghijklmnopqrst";
const size = 8, overlap = 2, step = size - overlap;
const chunks = [];
for (let i = 0; i < text.length; i += step) {
chunks.push(text.slice(i, i + size));
}
console.log(chunks.length);Your answer4 min · no timer
Show solution and explanation
The loop starts at 0, 6, 12 and 18. The start at 18 still pushes "st", which is already inside the previous chunk. Real chunkers usually stop once a chunk reaches the end of the text.
4