File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11function solution ( s ) {
2- return s . length % 2 === 0
3- ? s [ s . length / 2 - 1 ] + s [ s . length / 2 ]
4- : s [ Math . floor ( s . length / 2 ) ] ;
2+ const mid = s . length / 2 ;
3+ return s . length % 2 === 0 ? s [ mid - 1 ] + s [ mid ] : s [ Math . floor ( mid ) ] ;
54}
65
76// 다른 풀이
87// function solution(s) {
9- // return s.substr(Math.ceil(s.length / 2) - 1, s.length % 2 ? 1 : 2);
8+ // const mid = Math.floor(s.length / 2);
9+ // // 짝수면 mid-1부터 mid+1까지(2글자), 홀수면 mid부터 mid+1까지(1글자)
10+ // return s.length % 2 !== 0 ? s.slice(mid, mid + 1) : s.slice(mid - 1, mid + 1);
1011// }
Original file line number Diff line number Diff line change 1+ function solution ( n_str ) {
2+ let result = [ ] ;
3+ let foundFirstNonZero = false ;
4+
5+ for ( let i = 0 ; i < n_str . length ; i ++ ) {
6+ // 0이 아닌 숫자 처음 발견 & 그 자리가 0이 아닌 경우
7+ // 0이면 넘어가서 안 담기도록
8+ if ( ! foundFirstNonZero && n_str [ i ] !== "0" ) {
9+ foundFirstNonZero = true ;
10+ }
11+
12+ // 0이 아닌 숫자 처음 발견 이후 모든 문자 담기
13+ if ( foundFirstNonZero ) {
14+ result . push ( n_str [ i ] ) ;
15+ }
16+ }
17+
18+ return result . join ( "" ) ;
19+ }
20+
21+ // 다른 풀이
22+ // function solution(n_str) {
23+ // return String(Number(n_str));
24+ // }
Original file line number Diff line number Diff line change 1+ function solution ( str_list , ex ) {
2+ let answer = "" ;
3+ str_list . forEach ( ( list ) => {
4+ answer += list . includes ( ex ) ? "" : list ;
5+ } ) ;
6+ return answer ;
7+ }
8+
9+ // 다른 풀이
10+ function solution ( str_list , ex ) {
11+ // filter는 true를 거르는게 아닌 true를 포함시킴
12+ return str_list . filter ( ( str ) => ! str . includes ( ex ) ) . join ( "" ) ;
13+ }
Original file line number Diff line number Diff line change 1+ function solution ( arr ) {
2+ let min = Math . min ( ...arr ) ;
3+ return arr . length <= 1 ? [ - 1 ] : arr . filter ( ( n ) => n !== min ) ;
4+ }
You can’t perform that action at this time.
0 commit comments