-
Notifications
You must be signed in to change notification settings - Fork 4
[yulrang] 25.01.09 #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 14 commits
e12b51c
693472a
4c3882a
6684266
b4c4848
d35d6ff
01450c3
cfb6309
595c221
48065dc
fa79ae7
c812888
7d0245f
d155fbf
8ec1712
44de2be
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| function solution(numbers, num1, num2) { | ||
| var answer = []; | ||
|
|
||
| for(let i = num1; i <= num2; i++){ | ||
| answer.push(numbers[i]); | ||
| } | ||
| return answer; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| function solution(strlist) { | ||
| var answer = []; | ||
|
|
||
| for(let i=0; i<strlist.length; i++){ | ||
| answer.push(strlist[i].length); | ||
| } | ||
|
|
||
| return answer; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| function solution(numbers, direction) { | ||
| var answer = []; | ||
| if (direction === "left") { | ||
| for(let i=1; i<numbers.length; i++) { | ||
| answer.push(numbers[i]) | ||
| } | ||
| answer.push(numbers[0]); | ||
| } | ||
| if (direction === "right") { | ||
| answer.push(numbers[numbers.length-1]); | ||
| for(let i=0; i<numbers.length-1; i++) { | ||
| answer.push(numbers[i]) | ||
| } | ||
| } | ||
| return answer; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| function solution(array, n) { | ||
| var answer = 0; | ||
| var filteredArr = array.filter((el) => el === n); | ||
| answer = filteredArr.length; | ||
|
|
||
| return answer; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| function solution(arr) { | ||
| if (arr.length === 1) { | ||
| return [-1]; | ||
| } | ||
|
|
||
| return arr.filter((el) => el !== Math.min(...arr)); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| function solution(arr1, arr2) { | ||
| var answer = new Array(arr1.length); | ||
|
|
||
| for(let i=0; i<arr1.length; i++) { | ||
| answer[i] = new Array(arr1[i].length); | ||
| for(let j=0; j<arr1[i].length; j++) { | ||
| answer[i][j] = arr1[i][j] + arr2[i][j]; | ||
| } | ||
| } | ||
|
|
||
| return answer; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| function solution(arr, divisor) { | ||
| var answer = []; | ||
|
|
||
| arr.forEach((el) => { | ||
| if(el % divisor === 0) answer.push(el); | ||
| }) | ||
| answer.sort((a,b) => a-b); | ||
|
|
||
| if(answer.length === 0) return [-1]; | ||
|
|
||
| return answer; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| function solution(my_string) { | ||
| var answer = ''; | ||
| answer = my_string.split('').reverse().join(''); | ||
| return answer; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| function solution(s) { | ||
| var answer = 0; | ||
| let arr = s.split(' '); | ||
| let newArr = []; | ||
|
|
||
| for(let i=0; i<arr.length; i++) { | ||
| if( arr[i] !== 'Z' ) { | ||
| newArr.push(arr[i]); | ||
| } else { | ||
| newArr.pop(arr[i-1]) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. newArr.pop(); 으로 만 넣어도 될거같아요! |
||
| } | ||
| } | ||
| answer = newArr.reduce((acc, cur) => acc + Number(cur), 0); | ||
| return answer; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| function solution(numbers) { | ||
| var answer = 0; | ||
| const numberObj = { | ||
| zero : 0, | ||
| one : 1, | ||
| two : 2, | ||
| three : 3, | ||
| four : 4, | ||
| five : 5, | ||
| six : 6, | ||
| seven : 7, | ||
| eight : 8, | ||
| nine : 9, | ||
| } | ||
|
|
||
| for ( const num in numberObj ){ | ||
| numbers = numbers.replaceAll(num, numberObj[num]); | ||
| } | ||
| answer = Number(numbers); | ||
|
|
||
| return answer; | ||
| } |
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 매 순회마다 배열을 사용하고 배열의 값을 더한다음 배열을 변경하는 작업보다는 그냥 숫자를 직접 조작하는 방식이 더 좋을것 같아요!! 그리고 부호일 경우도 순회를 계속해서 불필요한 순회가 일어나고 있는거같아요. 이런식으로 순회를 줄일수도 있을거 같아요 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| function solution(my_string) { | ||
| var answer = 0; | ||
| let newArr = []; | ||
| my_string.split(' ').forEach((el, idx, arr) => { | ||
| if(idx === 0) { | ||
| newArr.push(Number(el)); | ||
| } | ||
| if(el === '+' || el === '-') { | ||
| newArr.push(Number(arr[idx + 1])) | ||
| if (el === '+'){ | ||
| answer = newArr[0] + newArr[1]; | ||
| } else { | ||
| answer = newArr[0] - newArr[1]; | ||
| } | ||
| newArr = []; | ||
| newArr.push(answer); | ||
| } | ||
| }) | ||
| answer = newArr[0]; | ||
| return answer; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| function solution(board, moves) { | ||
| let answer = 0; | ||
| let basket = []; | ||
|
|
||
| const runBasket = () => { | ||
| for(let i=basket.length-1; i>0; i--) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 전체 순회를 돌 필요는 없을 것 같아요! 이런식으로 돌수 있어요!! 그리고 slice메소드 보다는 pop 메소드가 더 시간 복잡도가 적습니다!! 근데 pop을 두번해야해서 지금상태도 괜찮을것 같아요 |
||
| if(basket[i] === basket[i-1]) { | ||
| basket.splice(i-1, 2); | ||
| answer += 2; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| for(let i=0; i<moves.length; i++) { | ||
| for(let j=0; j<board[0].length; j++) { | ||
| if(board[j][moves[i]-1] !== 0){ | ||
| basket.push(board[j][moves[i]-1]); | ||
| board[j][moves[i]-1] = 0; | ||
| runBasket(); | ||
| break; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return answer; | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이건 한줄로 작성해도 될거같아요!