mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-05 08:16:50 +08:00
merge: Add binary to decimal test file and convert function to es6 model. (#806)
* Added Hex to Binary conversion * Add Binary to decimal test * Fix Style
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
export const binaryToDecimal = (binaryString) => {
|
||||
export default function binaryToDecimal (binaryString) {
|
||||
let decimalNumber = 0
|
||||
const binaryDigits = binaryString.split('').reverse() // Splits the binary number into reversed single digits
|
||||
binaryDigits.forEach((binaryDigit, index) => {
|
||||
@ -6,9 +6,3 @@ export const binaryToDecimal = (binaryString) => {
|
||||
})
|
||||
return decimalNumber
|
||||
}
|
||||
|
||||
// > binaryToDecimal('111001')
|
||||
// 57
|
||||
|
||||
// > binaryToDecimal('101')
|
||||
// 5
|
||||
|
Reference in New Issue
Block a user