1
1
/**
2
2
* Converts an integer to an array representing its binary form.
3
3
*
4
- * @param {number } number - The integer to convert.
4
+ * @param {number } total - The integer to convert.
5
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 .
6
+ * @returns {Array<boolean> } An array of booleans representing the binary form of the total .
7
7
*/
8
- export function convert ( total , length , output = [ ] ) {
8
+ export function convert ( total , length = 32 , output = [ ] ) {
9
9
for ( let i = 0 ; i < length ; i ++ ) output [ i ] = ! ! ( total & ( 1 << i ) ) ;
10
10
11
11
return output ;
12
12
}
13
13
14
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.
15
+ * Performs a bitwise merge on a nested array input, each child being an array of booleans, using either OR or AND operation.
16
+ * Note: The nested arrays cannont have more then 32 boolean values due to JavaScript's limitation with bitwise operations.
17
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.
18
+ * @param {Array<Array<boolean>> } input - An array which holds arrays of the boolean values to be merged.
19
+ * @param {boolean } or - Determines bitwise operation to use. If true, OR; if false, AND.
20
20
* @returns {Array<boolean> } A boolean array representing the result of the bitwise merge operation.
21
21
*/
22
- export function BAM ( arrays = [ ] , or = true ) {
23
- if ( ! Array . isArray ( arrays ) || arrays . length === 0 || ! arrays . every ( arr => Array . isArray ( arr ) ) ) {
22
+ export function BAM ( input = [ ] , or = true ) {
23
+ if ( ! Array . isArray ( input ) || input . length === 0 || ! input . every ( arr => Array . isArray ( arr ) ) ) {
24
24
return [ ] ;
25
25
}
26
26
27
27
const data = {
28
- length : arrays . reduce (
28
+ length : input . reduce (
29
29
( accumulator , currentValue ) => {
30
30
if ( accumulator < currentValue . length ) return currentValue . length ;
31
31
return accumulator ;
@@ -49,11 +49,11 @@ export function BAM(arrays = [], or = true) {
49
49
data . total = set . max ;
50
50
}
51
51
52
- // Loop through the arrays and merge, if the value is 'complete' before all input merged, it will end.
53
- for ( let i = 0 ; i < arrays . length ; i ++ ) {
52
+ // Loop through the input and merge, if the value is 'complete' before all input merged, it will end.
53
+ for ( let i = 0 ; i < input . length ; i ++ ) {
54
54
if ( ( data . total = data . calc (
55
55
// Calculate a integer based on the input array, treating index and value like binary. [ false, true ] == 2 == 0 1
56
- arrays [ i ] . reduce ( ( total , value , index ) => ! ! value * Math . pow ( 2 , index ) + total , 0 )
56
+ input [ i ] . reduce ( ( total , value , index ) => ! ! value * Math . pow ( 2 , index ) + total , 0 )
57
57
) ) === data . complete ) break ;
58
58
}
59
59
0 commit comments