Skip to content

Commit 2b5ed8e

Browse files
authored
[moonjonghoo] 05.01.19 (#30)
* String_Reversal / 기초 * control_z / 기초 * I_don't_like_English /기초 * String_Calculation / 기초 * Crane_Doll_Picking_Game / 중급 * 순서쌍의_개수 / 기초 * 점의_위치_구하기 / 기초 * 로그인_성공? / 기초 * 특이한_정렬 / 기초 * 프로세스 / 고급 * 프로세스 /고급 수정
1 parent 61fb053 commit 2b5ed8e

File tree

5 files changed

+61
-0
lines changed

5 files changed

+61
-0
lines changed
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 (id === dbId) {
6+
return pw === dbPw ? "login" : "wrong pw";
7+
}
8+
}
9+
10+
return "fail";
11+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
function solution(n) {
2+
let count = 0;
3+
4+
for (let i = 1; i <= Math.sqrt(n); i++) {
5+
if (n % i === 0) {
6+
count++; // i가 약수
7+
if (i !== n / i) {
8+
count++; // i가 n의 제곱근이 아니면 나머지 짝도 추가
9+
}
10+
}
11+
}
12+
13+
return count;
14+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
function solution(dot) {
2+
const [x, y] = dot;
3+
4+
if (x > 0 && y > 0) return 1; // 1사분면
5+
if (x < 0 && y > 0) return 2; // 2사분면
6+
if (x < 0 && y < 0) return 3; // 3사분면
7+
if (x > 0 && y < 0) return 4; // 4사분면
8+
}
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 diffA = Math.abs(a - n);
4+
const diffB = Math.abs(b - n);
5+
6+
if (diffA === diffB) {
7+
return b - a;
8+
}
9+
return diffA - diffB;
10+
});
11+
}

Moonjonghoo/queue/프로세스.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
function solution(priorities, location) {
2+
let order = 0;
3+
4+
while (priorities.length > 0) {
5+
const current = priorities.shift();
6+
if (priorities.some((priority) => priority > current)) {
7+
priorities.push(current);
8+
location = location === 0 ? priorities.length - 1 : location - 1;
9+
} else {
10+
order++;
11+
if (location === 0) {
12+
return order; // 목표 프로세스가 실행되었을 때 순서를 반환
13+
}
14+
location--;
15+
}
16+
}
17+
}

0 commit comments

Comments
 (0)