Remove live code & console.log, leave examples as comments.

This commit is contained in:
Eric Lavault
2021-10-11 14:07:10 +02:00
parent 90356f340d
commit e18718b7d5
14 changed files with 64 additions and 59 deletions

View File

@ -1,15 +1,12 @@
const binaryToDecimal = (binaryString) => {
export const binaryToDecimal = (binaryString) => {
let decimalNumber = 0
const binaryDigits = binaryString.split('').reverse() // Splits the binary number into reversed single digits
binaryDigits.forEach((binaryDigit, index) => {
decimalNumber += binaryDigit * (Math.pow(2, index)) // Summation of all the decimal converted digits
})
console.log(`Decimal of ${binaryString} is ${decimalNumber}`)
return decimalNumber
}
export { binaryToDecimal }
// > binaryToDecimal('111001')
// 57