export class Binary {
constructor(binary) {
this.binary = binary;
}
toDecimal() {
if (/[^01]/.test(this.binary)) return 0;
return [...this.binary].reduce((acc, digit, index) => {
return acc + Number(digit) * Math.pow(2, this.binary.length - 1 - index);
}, 0);
}
}