File tree Expand file tree Collapse file tree 1 file changed +16
-3
lines changed Expand file tree Collapse file tree 1 file changed +16
-3
lines changed Original file line number Diff line number Diff line change 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
+ */
2
8
export function convert ( total , length , output = [ ] ) {
3
9
for ( let i = 0 ; i < length ; i ++ ) output [ i ] = ! ! ( total & ( 1 << i ) ) ;
4
10
5
11
return output ;
6
12
}
7
13
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
+ */
9
22
export function BAM ( arrays = [ ] , or = true ) {
10
- if ( ! Array . isArray ( arrays ) ) return false ;
23
+ if ( ! Array . isArray ( arrays ) || arrays . length === 0 ) return [ ] ;
11
24
12
25
const data = {
13
26
length : arrays . reduce (
You can’t perform that action at this time.
0 commit comments