-
Notifications
You must be signed in to change notification settings - Fork 4
[unn04012] 25.01.16 #29
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 all commits
c942abf
0bbc32d
73a4661
a3b4f62
2360efc
3e0c123
02ec602
8803f24
c34eecd
1f6fd0b
cee4b18
24561a7
818f307
b5046ab
421ec9c
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,12 @@ | ||
| function solution(arr, divisor) { | ||
| const answer = []; | ||
|
|
||
| for (const e of arr) { | ||
| if (e % divisor === 0) answer.push(e); | ||
| } | ||
| if (answer.length === 0) answer.push(-1); | ||
|
|
||
| return answer.sort((a, b) => a - b); | ||
| } | ||
|
|
||
| console.log(solution([5, 9, 7, 10], 5)); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| function solution(arr1, arr2) { | ||
| const n = arr1.length; | ||
| const m = arr2[0].length; | ||
|
|
||
| const answer = Array.from({ length: n }, () => Array(m).fill(0)); | ||
|
|
||
| for (let i = 0; i < n; i++) { | ||
| for (let j = 0; j < m; j++) { | ||
| const result = arr1[i].reduce((acc, cur, idx) => acc + cur * arr2[idx][j], 0); | ||
|
|
||
| answer[i][j] = result; | ||
| } | ||
| } | ||
|
|
||
| return answer; | ||
| } | ||
|
|
||
| console.log( | ||
| solution( | ||
| [ | ||
| [2, 3, 2], | ||
| [4, 2, 4], | ||
| [3, 1, 4], | ||
| ], | ||
| [ | ||
| [5, 4, 3], | ||
| [2, 4, 1], | ||
| [3, 1, 1], | ||
| ] | ||
| ) | ||
| ); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| function solution(numbers, direction) { | ||
| const answer = []; | ||
|
|
||
| if (direction === 'right') { | ||
| for (let i = 0; i < numbers.length - 1; i++) { | ||
| answer[i + 1] = numbers[i]; | ||
| } | ||
| answer[0] = numbers[numbers.length - 1]; | ||
| } else { | ||
| for (let i = numbers.length - 1; i >= 1; i--) { | ||
| answer[i - 1] = numbers[i]; | ||
| } | ||
| answer[numbers.length - 1] = numbers[0]; | ||
| } | ||
|
|
||
| return answer; | ||
| } | ||
|
|
||
| console.log(solution([4, 455, 6, 4, -1, 45, 6], 'left')); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| function solution(numbers, num1, num2) { | ||
| const answer = []; | ||
|
|
||
| for (let i = num1; i <= num2; i++) answer.push(numbers[i]); | ||
|
|
||
| return answer; | ||
| } | ||
|
|
||
| console.log(solution([1, 2, 3, 4, 5], 1, 3)); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| function solution(arr) { | ||
| const answer = []; | ||
| const minNum = Math.min(...arr); | ||
|
|
||
| for (const e of arr) { | ||
| if (e === minNum) continue; | ||
| answer.push(e); | ||
| } | ||
| return answer.length ? answer : [-1]; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| function solution(n) { | ||
| const divisors = []; | ||
|
|
||
| for (let i = 1; i <= n; i++) if (n % i === 0) divisors.push(i); | ||
| return divisors.length; | ||
| } | ||
|
|
||
| console.log(solution(100)); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| function solution(cards1, cards2, goal) { | ||
| const reversedCard1 = cards1.reverse(); | ||
| const reversedCard2 = cards2.reverse(); | ||
|
Comment on lines
+2
to
+3
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. reverse & popμ μ¬μ©νλ©΄ shiftλ₯Ό μ¬μ©νλ κ²λ³΄λ€ μκ° λ³΅μ‘λ λ©΄μμ λ ν¨μ¨μ μ΄κ΅°μ. λ°°μκ°λλ€! |
||
|
|
||
| for (const word of goal) { | ||
| let flag = false; | ||
| if (reversedCard1[reversedCard1.length - 1] === word) { | ||
| reversedCard1.pop(); | ||
| flag = true; | ||
| } else if (reversedCard2[reversedCard2.length - 1] === word) { | ||
| reversedCard2.pop(); | ||
| flag = true; | ||
| } | ||
| if (!flag) return 'No'; | ||
| } | ||
|
|
||
| return 'Yes'; | ||
| } | ||
|
|
||
| console.log(solution(['i', 'drink', 'water'], ['want', 'to'], ['i', 'want', 'to', 'drink', 'water'])); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| function solution(dot) { | ||
| let answer = 0; | ||
| const [x, y] = dot; | ||
|
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. μ΄ μ½λλ μ¬μ©μνλκ±°κ°μμ! |
||
|
|
||
| const quadrant = [ | ||
| [1, 1], | ||
| [-1, 1], | ||
| [-1, -1], | ||
| [1, -1], | ||
| ]; | ||
|
|
||
| for (let i = 0; i < quadrant.length; i++) { | ||
| const [x, y] = quadrant[i]; | ||
|
|
||
| const newX = x * dot[0]; | ||
| const newY = y * dot[1]; | ||
|
|
||
| if (newX > 0 && newY > 0) { | ||
| answer = i + 1; | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| return answer; | ||
| } | ||
|
|
||
| console.log(solution([-7, 9])); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| function solution(ingredients) { | ||
| let answer = 0; | ||
| const queue = []; | ||
|
|
||
| for (const ingredient of ingredients) { | ||
| queue.push(ingredient); | ||
| if (queue.length >= 4) { | ||
| const hamburger = queue.slice(-4).join(''); | ||
|
|
||
| if (hamburger === '1231') { | ||
| answer++; | ||
| for (let i = 0; i < 4; i++) queue.pop(); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return answer; | ||
| } | ||
|
|
||
| console.log(solution([2, 1, 1, 2, 3, 1, 2, 3, 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. μ΄ μ½λμμ queue λ°°μ΄μ΄ λ±ν μ°μ μμ κ°μ λ΄λ κ² λ§κ³ μ¬μ©μ΄ λμ§ μλ κ² κ°μμ. νΉμ λ€λ₯Έ μλκ° μμλμ§ κΆκΈν©λλ€! |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| function solution(priorities, location) { | ||
| let answer = 1; | ||
| const queue = []; | ||
|
|
||
| const prioritiesWithIndex = priorities.map((priority, index) => ({ priority, index })); | ||
|
|
||
| while (prioritiesWithIndex.length) { | ||
| const { priority, index } = prioritiesWithIndex.shift(); | ||
|
|
||
| const checkPriority = prioritiesWithIndex.findIndex((e) => e.priority > priority); | ||
|
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. some λ©μλλ₯Ό κ³ λ €ν΄ λ³΄μλ건 μ΄λ¨κΉμ?? |
||
|
|
||
| // μ°μ μμκ° λ ν° νλ‘μΈμ€κ° μμΌλ©΄ | ||
| if (checkPriority === -1) { | ||
| if (location === index) return queue.length + 1; | ||
| queue.push(priority); | ||
| continue; | ||
| } | ||
|
|
||
| prioritiesWithIndex.push({ priority, index }); | ||
| } | ||
|
|
||
| return answer; | ||
| } | ||
| console.log(solution([1, 1, 9, 1, 1, 1], 0)); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| function solution(board, moves) { | ||
| let answer = 0; | ||
| const stack = []; | ||
| const width = board.length; | ||
|
|
||
| const pullCrane = (order) => { | ||
| const w = order - 1; | ||
| let h = 0; | ||
|
|
||
| while (width > h) { | ||
| const doll = board[h][w]; | ||
| if (doll !== 0) { | ||
| if (stack[stack.length - 1] === doll) { | ||
| stack.pop(); | ||
| answer += 2; | ||
| } else { | ||
| stack.push(board[h][w]); | ||
| } | ||
|
|
||
| board[h][w] = 0; | ||
| break; | ||
| } | ||
| h++; | ||
| } | ||
| }; | ||
|
|
||
| moves.forEach((e) => pullCrane(e)); | ||
|
|
||
| return answer; | ||
| } | ||
|
|
||
| console.log( | ||
| solution( | ||
| [ | ||
| [0, 0, 0, 0, 0], | ||
| [0, 0, 1, 0, 3], | ||
| [0, 2, 5, 0, 1], | ||
| [4, 2, 4, 4, 2], | ||
| [3, 5, 1, 3, 1], | ||
| ], | ||
| [1, 5, 3, 5, 1, 2, 1, 4] | ||
| ) | ||
| ); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| function solution(numbers) { | ||
| let answer = numbers; | ||
| const englishObj = { | ||
| zero: 0, | ||
| one: 1, | ||
| two: 2, | ||
| three: 3, | ||
| four: 4, | ||
| five: 5, | ||
| six: 6, | ||
| seven: 7, | ||
| eight: 8, | ||
| nine: 9, | ||
| }; | ||
|
|
||
| for (const [key, value] of Object.entries(englishObj)) { | ||
| if (numbers.includes(key)) { | ||
| answer = answer.replaceAll(key, value); | ||
| } | ||
| } | ||
|
|
||
| return Number(answer); | ||
| } | ||
|
|
||
| console.log(solution('onefourzerosixseven')); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| function solution(s) { | ||
| const stack = []; | ||
| let answer = 0; | ||
|
|
||
| s.split(' ').forEach((e) => { | ||
| // μ«μκ° μλλ©΄ | ||
| if (Number.isNaN(Number(e))) { | ||
| answer -= stack.pop(); | ||
| } else { | ||
| const num = Number(e); | ||
| answer += num; | ||
| stack.push(num); | ||
| } | ||
| }); | ||
|
|
||
| return answer; | ||
| } | ||
|
|
||
| console.log(solution('10 Z 20 Z')); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| function solution(my_string) { | ||
| let answer = 0; | ||
|
|
||
| const expression = my_string.split(' ').reverse(); | ||
|
|
||
| while (expression.length) { | ||
| const element = expression.pop(); | ||
|
|
||
| if (element === '+') { | ||
| answer += Number(expression.pop()); | ||
| expression.push(answer); | ||
| } else if (element === '-') { | ||
| answer -= Number(expression.pop()); | ||
| expression.push(answer); | ||
| } else { | ||
| // μ«μμΈ κ²½μ° | ||
| answer = Number(element); | ||
| } | ||
| } | ||
|
|
||
| return answer; | ||
| } | ||
|
|
||
| console.log(solution('3 + 4 - 2')); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| function solution(my_string) { | ||
| return my_string.split('').reverse().join(''); | ||
| } | ||
|
|
||
| console.log(solution('jaron')); |
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.
λ¨μν κΈΈμ΄λ₯Ό λ°ννλ κ±°λΌλ©΄ const divisors = [];λ₯Ό count λ‘ κ°μ Έκ°λκ² λ©λͺ¨λ¦¬μ μΌλ‘ λ μ’μκ² κ°μμ