Skip to content
Advertisement

converting number bases to string using a recursive function javascript

I’m trying to write a recursive function that takes two parameters – an integer input, n, and an integer base, m – and returns a string representation of the number in Base m. I’m stuck can someone help?

JavaScript

Advertisement

Answer

You forgot to include base in recursive call

And to reduce complexity, the base case of this recursion call is to check whether n is zero, then return empty string to concat with the returned from upper stack call

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement