1.1.4 • Published 2 years ago

chunki v1.1.4

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

chunki has two utility functions:

  • One to split an array into smaller chunks.
  • Another to combine chunks into a single array.

Chunk Method

const { chunk } = require("chunki");

// If you are using es6 import feature
//import { chunk } = from "chunki";

const arr = [1, 2, 3, 4, 5, 6];
const chunks = chunk(arr, 2); // 2 --> chunk size
console.log(chunks); // [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ]

//Splitting objects into chunks
const arr = [{ name: "john" }, { name: "Patlu" }];
const chunks = chunk(arr, 1);
console.log(chunks); //[ [ { name: 'john' } ], [ { name: 'Patlu' } ] ]

Flatten Method

const { flatten } = require("chunki");

// If you are using es6 import feature
//import {  flatten } = from "chunki";
const chunks = [
  [1, 2],
  [3, 4],
  [5, 6],
];
const flattenArr = flatten(chunks);
console.log(flattenArr); //[ 1, 2, 3, 4, 5, 6 ]
1.1.1

2 years ago

1.1.0

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.1.4

2 years ago

1.0.5

2 years ago

1.1.3

2 years ago

1.0.4

2 years ago

1.1.2

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago