Convert boolean array to integer in Typescript
Binary Math
Using string to do integer maths is very slow. You can use bitwise operators to encode and decode bit fields.
Encode bool array to int
The first function sets the low bit depending on the boolean. Each iteration the bits set are shifted to the left. The result is that the first array item is the highest bit (bit 7) and the last day is the lowest bit (bit 1)
Decode int to bool array
The second uses bitwise AND &amp; to mask out all but the bit position required and adds a boolean to an array depending on the state of the bit.


// high bit is first item in days eg 0b1000000 is day[0]
function serializeDays(days) { 
     return days.reduce((bin, day) =&gt; (bin &lt;&lt; 1) + (!!day), 0);
} 

function parseDays(bitField) {
     var bit = 7, days = [];
     while (bit) { days.push((bitField &amp; (1 &lt;&lt; --bit)) !== 0) }
     return days;
}
    
      
console.log(serializeDays([true,false,true,false,true,false,true]).toString(2));      
console.log(parseDays(0b1010101).join(","));