Skip to content

Commit f0acbb9

Browse files
committed
Add docblock and extra check
1 parent edcb657 commit f0acbb9

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

index.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,26 @@
1-
// Convert integers into arrays based on base 2, binary.
1+
/**
2+
* Converts an integer to an array representing its binary form.
3+
*
4+
* @param {number} number - The integer to convert.
5+
* @param {number} length - The length of the resulting binary array.
6+
* @returns {Array<boolean>} An array of booleans representing the binary form of the number.
7+
*/
28
export function convert(total, length, output = []) {
39
for (let i = 0; i < length; i++) output[i] = !!(total & (1 << i));
410

511
return output;
612
}
713

8-
// Binary array merge, array input can't have more then 32 values because of JavaScript limatation with bitwise operations.
14+
/**
15+
* Performs a bitwise merge on an array of boolean arrays using either OR or AND operation.
16+
* Note: The input arrays cannot have more than 32 values due to JavaScript's limitation with bitwise operations.
17+
*
18+
* @param {Array<Array<boolean>>} arrays - An array of boolean arrays to be merged.
19+
* @param {boolean} or - Determines the type of bitwise operation to use. If true, uses OR; if false, uses AND.
20+
* @returns {Array<boolean>} A boolean array representing the result of the bitwise merge operation.
21+
*/
922
export function BAM(arrays = [], or = true) {
10-
if (!Array.isArray(arrays)) return false;
23+
if (!Array.isArray(arrays) || arrays.length === 0) return [];
1124

1225
const data = {
1326
length: arrays.reduce(

0 commit comments

Comments
 (0)