Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Maths/BinaryConvert.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const BinaryConvert = (number) => {
const result = []
let i
for (i = number; i > 0; i = parseInt(i / 2)) {
result.push(i % 2) // push the value (remainder)to array
} return Number(result.reverse().join(''))
// reverse index of array as string ,join and change the type of value to become Number
}
// call function and value as parameter to passing the value
export { BinaryConvert }
10 changes: 10 additions & 0 deletions Maths/test/BInaryConvert.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { BinaryConvert } from '../BinaryConvert'

describe('Binary Convert', () => {
it('should return the correct value', () => {
expect(BinaryConvert(12)).toBe(1100)
})
it('should return the correct value of the sum from two number', () => {
expect(BinaryConvert(12 + 2)).toBe(1110)
})
})
Loading