← Back to challenges

Complete the Binary Number

JavaScriptHardlanguage_fundamentalsstringsformatting

Instructions

Create a function which adds zeros to the start of a binary string, so that its length is a multiple of 8.

Examples

completeBinary("1100") ➞ "00001100"

completeBinary("1101100") ➞ "01101100"

completeBinary("110010100010") ➞ "0000110010100010"

Notes

Return the same string if its length is already a multiple of 8.

javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: ES6: Destructuring Objects V