← Back to challenges

Rearrange the Number

JavaScriptHardsortingnumbers

Instructions

Given a number, return the difference between the maximum and minimum numbers that can be formed when the digits are rearranged.

Examples

rearrangedDifference(972882) ➞ 760833
// 988722 - 227889 = 760833

rearrangedDifference(3320707) ➞ 7709823
// 7733200 - 23377 = 7709823

rearrangedDifference(90010) ➞ 90981
// 91000 - 19 = 90981

Notes

N/A

javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Planetary Weight Converter