File tree Expand file tree Collapse file tree 5 files changed +116
-0
lines changed
Expand file tree Collapse file tree 5 files changed +116
-0
lines changed Original file line number Diff line number Diff line change 1+ function solution ( board , moves ) {
2+ let answer = 0 ;
3+ const stack = [ ] ;
4+ const width = board . length ;
5+
6+ const pullCrane = ( order ) => {
7+ const w = order - 1 ;
8+ let h = 0 ;
9+
10+ while ( width > h ) {
11+ const doll = board [ h ] [ w ] ;
12+ if ( doll !== 0 ) {
13+ if ( stack [ stack . length - 1 ] === doll ) {
14+ stack . pop ( ) ;
15+ answer += 2 ;
16+ } else {
17+ stack . push ( board [ h ] [ w ] ) ;
18+ }
19+
20+ board [ h ] [ w ] = 0 ;
21+ break ;
22+ }
23+ h ++ ;
24+ }
25+ } ;
26+
27+ moves . forEach ( ( e ) => pullCrane ( e ) ) ;
28+
29+ return answer ;
30+ }
31+
32+ console . log (
33+ solution (
34+ [
35+ [ 0 , 0 , 0 , 0 , 0 ] ,
36+ [ 0 , 0 , 1 , 0 , 3 ] ,
37+ [ 0 , 2 , 5 , 0 , 1 ] ,
38+ [ 4 , 2 , 4 , 4 , 2 ] ,
39+ [ 3 , 5 , 1 , 3 , 1 ] ,
40+ ] ,
41+ [ 1 , 5 , 3 , 5 , 1 , 2 , 1 , 4 ]
42+ )
43+ ) ;
Original file line number Diff line number Diff line change 1+ function solution ( numbers ) {
2+ let answer = numbers ;
3+ const englishObj = {
4+ zero : 0 ,
5+ one : 1 ,
6+ two : 2 ,
7+ three : 3 ,
8+ four : 4 ,
9+ five : 5 ,
10+ six : 6 ,
11+ seven : 7 ,
12+ eight : 8 ,
13+ nine : 9 ,
14+ } ;
15+
16+ for ( const [ key , value ] of Object . entries ( englishObj ) ) {
17+ if ( numbers . includes ( key ) ) {
18+ answer = answer . replaceAll ( key , value ) ;
19+ }
20+ }
21+
22+ return Number ( answer ) ;
23+ }
24+
25+ console . log ( solution ( 'onefourzerosixseven' ) ) ;
Original file line number Diff line number Diff line change 1+ function solution ( s ) {
2+ const stack = [ ] ;
3+ let answer = 0 ;
4+
5+ s . split ( ' ' ) . forEach ( ( e ) => {
6+ // 숫자가 아니면
7+ if ( Number . isNaN ( Number ( e ) ) ) {
8+ answer -= stack . pop ( ) ;
9+ } else {
10+ const num = Number ( e ) ;
11+ answer += num ;
12+ stack . push ( num ) ;
13+ }
14+ } ) ;
15+
16+ return answer ;
17+ }
18+
19+ console . log ( solution ( '10 Z 20 Z' ) ) ;
Original file line number Diff line number Diff line change 1+ function solution ( my_string ) {
2+ let answer = 0 ;
3+
4+ const expression = my_string . split ( ' ' ) . reverse ( ) ;
5+
6+ while ( expression . length ) {
7+ const element = expression . pop ( ) ;
8+
9+ if ( element === '+' ) {
10+ answer += Number ( expression . pop ( ) ) ;
11+ expression . push ( answer ) ;
12+ } else if ( element === '-' ) {
13+ answer -= Number ( expression . pop ( ) ) ;
14+ expression . push ( answer ) ;
15+ } else {
16+ // 숫자인 경우
17+ answer = Number ( element ) ;
18+ }
19+ }
20+
21+ return answer ;
22+ }
23+
24+ console . log ( solution ( '3 + 4 - 2' ) ) ;
Original file line number Diff line number Diff line change 1+ function solution ( my_string ) {
2+ return my_string . split ( '' ) . reverse ( ) . join ( '' ) ;
3+ }
4+
5+ console . log ( solution ( 'jaron' ) ) ;
You can’t perform that action at this time.
0 commit comments