mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-05 08:16:50 +08:00
Remove live code & console.log, leave examples as comments.
This commit is contained in:
@ -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
|
||||
|
||||
|
Reference in New Issue
Block a user