Skip to content

Commit 4790475

Browse files
authored
[oh-chaeyeon] 25.01.16 (#28)
* 배열 자르기 / 기초 * 배열 원소의 길이 / 기초 * 배열 회전시키기 / 기초 * 중복된 숫자 개수 / 기초 * 제일 작은 수 제거하기 / 중급 * 행렬의 덧셈 / 중급 * 나누어 떨어지는 숫자 배열 / 중급 * 행렬의 곱셈 / 심화 * 교점에 별 만들기 / 심화 * n^2 배열 자르기 / 심화 * String Reversal / 기초 * Control Z / 기초 * Hate English / 기초 * String Calculation / 기초 * Crane Game / 중급 * Valid Parentheses / 중급 * Dart Game / 중급 * Rotate Parentheses / 심화 * Stock Price / 심화 * Delivery Box / 심화 * 순서쌍의 개수 / 기초 * 점의 위치 구하기 / 기초 * 로그인 성공? / 기초 * 특이한 정렬 / 기초 * 카드 뭉치 / 중급 * 공원 산책 / 중급 * 햄버거 만들기 / 중급
1 parent cf0bad6 commit 4790475

File tree

7 files changed

+123
-0
lines changed

7 files changed

+123
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
function solution(cards1, cards2, goal) {
2+
const q1 = [...cards1];
3+
const q2 = [...cards2];
4+
5+
for (const word of goal) {
6+
if (q1.length > 0 && q1[0] === word) {
7+
q1.shift();
8+
} else if (q2.length > 0 && q2[0] === word) {
9+
q2.shift();
10+
} else {
11+
return "No";
12+
}
13+
}
14+
return "Yes";
15+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
function solution(dot) {
2+
const x = dot[0];
3+
const y = dot[1];
4+
5+
switch (true) {
6+
case x > 0 && y > 0:
7+
return 1;
8+
case x < 0 && y > 0:
9+
return 2;
10+
case x < 0 && y < 0:
11+
return 3;
12+
case x > 0 && y < 0:
13+
return 4;
14+
}
15+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
function solution(id_pw, db) {
2+
const [id, pw] = id_pw;
3+
4+
for (const [dbId, dbPw] of db) {
5+
if (dbId === id) {
6+
return dbPw === pw ? "login" : "wrong pw";
7+
}
8+
}
9+
10+
return "fail";
11+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
function solution(ingredient) {
2+
const q = [];
3+
let count = 0;
4+
5+
for (const item of ingredient) {
6+
q.push(item);
7+
8+
if (q.length >= 4 && q.slice(-4).join("") === "1231") {
9+
q.splice(-4);
10+
count++;
11+
}
12+
}
13+
14+
return count;
15+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
function solution(n) {
2+
let num = 0;
3+
for (let i = 1; i * i <= n; i++) {
4+
if (n % i === 0) {
5+
num += 2;
6+
if (i * i === n) {
7+
num--;
8+
}
9+
}
10+
}
11+
return num;
12+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
function solution(numlist, n) {
2+
return numlist.sort((a, b) => {
3+
const A = Math.abs(a - n);
4+
const B = Math.abs(b - n);
5+
6+
if (A === B) {
7+
return b - a;
8+
}
9+
return A - B;
10+
});
11+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
function solution(park, routes) {
2+
const directions = { N: [-1, 0], S: [1, 0], W: [0, -1], E: [0, 1] };
3+
let x, y;
4+
5+
for (let i = 0; i < park.length; i++) {
6+
const j = park[i].indexOf("S");
7+
if (j !== -1) {
8+
x = i;
9+
y = j;
10+
break;
11+
}
12+
}
13+
14+
for (const route of routes) {
15+
const [direction, distanceStr] = route.split(" ");
16+
const distance = parseInt(distanceStr);
17+
const [dx, dy] = directions[direction];
18+
19+
let canMove = true;
20+
21+
for (let step = 1; step <= distance; step++) {
22+
const newX = x + dx * step;
23+
const newY = y + dy * step;
24+
25+
if (
26+
newX < 0 ||
27+
newX >= park.length ||
28+
newY < 0 ||
29+
newY >= park[0].length ||
30+
park[newX][newY] === "X"
31+
) {
32+
canMove = false;
33+
break;
34+
}
35+
}
36+
37+
if (canMove) {
38+
x += dx * distance;
39+
y += dy * distance;
40+
}
41+
}
42+
43+
return [x, y];
44+
}

0 commit comments

Comments
 (0)