Convert to Base | Time: O(log(N)) | Space: O(log(N))
Complexity\n- Time complexity: $O(\log{N})$\n- Space complexity: $O(\log{N})$\n\n# Code 1: Number.toString\nUses the built-in base conversion feature of Number.
# Complexity\n- Time complexity: $O(\\log{N})$\n- Space complexity: $O(\\log{N})$\n\n# Code 1: Number.toString\nUses the built-in base conversion feature of [Number.toString](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toString). It can convert a number to a string in any base from 2 to 36.\n\n```Typescript\nfunction convertToBase7(num: number): string {\n   return num.toString(7);\n};\n```\n \n# Code 2: Custom\nManually converts the number to base 7. Works for bases from 2 to 10.\n```Typescript\nfunction convertToBase7(num: number): string {\n   return toBase(num, 7);\n};\n\nfunction toBase(num: number, base: number): string {\n    const res: number[] = [];\n    const sign = Math.sign(num);\n    num *= sign;\n    while (num >= base) {\n        const digit = num % base;\n        num = (num - digit) / base;\n        res.push(digit);\n    }\n    res.push(sign * num);\n    return res.reverse().join("");\n}\n```\n\n# Code 3: Custom Extended\nManually converts the number to base 7. Works for bases from 2 to 36. It can be easily extended for higher bases and/or for custom mappings.\n\n```Typescript\nconst SYMBOLS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";\n\nfunction convertToBase7(num: number): string {\n   return toBase(num, 7);\n};\n\nfunction toBase(num: number, base: number, symbols = SYMBOLS): string {\n    const res: string[] = [];\n    const sign = Math.sign(num);\n    num *= sign;\n    do {\n        const digit = num % base;\n        num = (num - digit) / base;\n        res.push(symbols[digit]);\n    } while (num > 0);\n    (sign < 0) && res.push("-");\n    return res.reverse().join("");\n}\n```
['TypeScript', 'JavaScript']