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:
Dhana D
2021-10-24 00:46:13 +07:00
committed by GitHub
parent 4ba2c32d78
commit d5e309b605
4 changed files with 72 additions and 7 deletions

View File

@ -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