mirror of
https://github.com/netbymatt/ws4kp.git
synced 2026-04-18 17:49:31 -07:00
refresh data sources close #73
This commit is contained in:
22
datagenerators/chunk.mjs
Normal file
22
datagenerators/chunk.mjs
Normal file
@@ -0,0 +1,22 @@
|
||||
// turn a long array into a set of smaller chunks
|
||||
|
||||
const chunk = (data, chunkSize = 10) => {
|
||||
const chunks = [];
|
||||
|
||||
let thisChunk = [];
|
||||
|
||||
data.forEach((d) => {
|
||||
if (thisChunk.length >= chunkSize) {
|
||||
chunks.push(thisChunk);
|
||||
thisChunk = [];
|
||||
}
|
||||
thisChunk.push(d);
|
||||
});
|
||||
|
||||
// final chunk
|
||||
if (thisChunk.length > 0) chunks.push(thisChunk);
|
||||
|
||||
return chunks;
|
||||
};
|
||||
|
||||
export default chunk;
|
||||
Reference in New Issue
Block a user