← Back to challenges

Positive Integer Into Base 2, 8 and 16

JavaScriptHardrecursionlogic

Instructions

Create a function that takes a positive integer number (one of base2, base8, or base16) and converts the integer into the given base and returns a string using recursion.

Examples

integerToString(10 , 2) ➞ "1010"
// Base = 2

integerToString(1642 , 8) ➞ "3152"
// Base = 8

integerToString(212 , 16) ➞ "d4"
// Base = 16

Notes

  • Input is a positive integer and base = 2, 8, or 16.
  • Please use recursion to solve this.
javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: String Slice-athon