-
Notifications
You must be signed in to change notification settings - Fork 0
/
7kyu-form-the-largest.js
55 lines (34 loc) · 1.48 KB
/
7kyu-form-the-largest.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Task
// Given a number , Return _The Maximum number _ could be formed from the digits of the number given .
// Notes
// Only Positve numbers passed to the function , numbers Contain digits [1:9] inclusive !alt !alt
// Digit Duplications could occur , So also consider it when forming the Largest !alt
// Input >> Output Examples:
// maxNumber (213) ==> return (321)
// Explanation:
// As 321 is _The Maximum number _ could be formed from the digits of the number *213*** .
// maxNumber (7389) ==> return (9873)
// Explanation:
// As 9873 is _The Maximum number _ could be formed from the digits of the number *7389*** .
// maxNumber (63729) ==> return (97632)
// Explanation:
// As 97632 is _The Maximum number _ could be formed from the digits of the number *63729*** .
// maxNumber (566797) ==> return (977665)
// Explanation:
// As 977665 is _The Maximum number _ could be formed from the digits of the number *566797*** .
// Note : Digit duplications are considered when forming the largest .
// maxNumber (17693284) ==> return (98764321)
// Explanation:
// As 98764321 is _The Maximum number _ could be formed from the digits of the number *17693284*** .
// Playing with Numbers Series
// Playing With Lists/Arrays Series
// For More Enjoyable Katas
// ALL translations are welcomed
// Enjoy Learning !!
// Zizou
function maxNumber(n) {
const nArray = String(n)
.split('')
.sort((a, b) => b - a);
return Number(nArray.join(''));
}