mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-05 08:16:50 +08:00
Fix methodname and parameter type in BinaryToDecimal.js (#392)
* Update BinaryToDecimal.js Fix typo in name * Update BinaryToDecimal.js Co-authored-by: vinayak <itssvinayak@gmail.com>
This commit is contained in:
@ -1,11 +1,14 @@
|
|||||||
function binaryToDeicmal (binaryNumber) {
|
const binaryToDecimal = (binaryString) => {
|
||||||
let decimalNumber = 0
|
let decimalNumber = 0
|
||||||
const binaryDigits = binaryNumber.split('').reverse() // Splits the binary number into reversed single digits
|
const binaryDigits = binaryString.split('').reverse() // Splits the binary number into reversed single digits
|
||||||
binaryDigits.forEach((binaryDigit, index) => {
|
binaryDigits.forEach((binaryDigit, index) => {
|
||||||
decimalNumber += binaryDigit * (Math.pow(2, index)) // Summation of all the decimal converted digits
|
decimalNumber += binaryDigit * (Math.pow(2, index)) // Summation of all the decimal converted digits
|
||||||
})
|
})
|
||||||
console.log(`Decimal of ${binaryNumber} is ${decimalNumber}`)
|
console.log(`Decimal of ${binaryString} is ${decimalNumber}`)
|
||||||
|
return decimalNumber
|
||||||
}
|
}
|
||||||
|
|
||||||
binaryToDeicmal('111001')
|
(() => {
|
||||||
binaryToDeicmal('101')
|
binaryToDecimal('111001')
|
||||||
|
binaryToDecimal('101')
|
||||||
|
})()
|
||||||
|
Reference in New Issue
Block a user