File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -22,4 +22,33 @@ function solution(numbers) {
22
22
numbers . map ( ( el ) => el + '' ) . sort ( ( a , b ) => ( b + a ) - ( a + b ) ) ;
23
23
24
24
return stringNum [ 0 ] === '0' ? '0' : stringNum . join ( '' ) ;
25
+ }
26
+
27
+ //완벽한 정답이 아닙니다.
28
+ // 정답 3 - prove-ability
29
+ function solution ( numbers ) {
30
+ if ( numbers . every ( v => v === 0 ) ) return "0" ;
31
+ return numbers . sort ( ( a , b ) => {
32
+ if ( a === b ) return 0 ;
33
+ let stringA = a . toString ( 10 ) , stringB = b . toString ( 10 ) ;
34
+ if ( stringA [ 0 ] === stringB [ 0 ] ) {
35
+ let aIndex = 1 , bIndex = 1 ;
36
+ while ( true ) {
37
+ if ( ! stringA [ aIndex ] ) -- aIndex ;
38
+ if ( ! stringB [ bIndex ] ) -- bIndex ;
39
+ if ( stringA [ aIndex ] === stringB [ bIndex ] ) {
40
+ aIndex ++ , bIndex ++ ;
41
+ continue ;
42
+ }
43
+ if ( stringA [ aIndex ] < stringB [ bIndex ] ) return 1 ;
44
+ else return - 1 ;
45
+ }
46
+ }
47
+ return stringB [ 0 ] - stringA [ 0 ]
48
+ } ) . join ( "" ) ;
49
+ }
50
+
51
+ // 정답 4 - prove-ability
52
+ function solution ( numbers ) {
53
+ return numbers . every ( v => v === 0 ) ? "0" : numbers . map ( v => v . toString ( 10 ) ) . sort ( ( a , b ) => ( b + a ) - ( a + b ) ) . join ( "" ) ;
25
54
}
You can’t perform that action at this time.
0 commit comments