Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit db2925a

Browse files
feat: level 0 풀이 완료
1 parent 10a301f commit db2925a

19 files changed

+211
-65
lines changed

‎level-0/OX퀴즈&120907&.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
//https://github.com/codeisneverodd/programmers-coding-test
22
//완벽한 정답이 아닙니다.
33
//정답 1 - codeisneverodd
4-
function solution(n) {
5-
//프로그래머스에 제출하여 통과된 함수를 복사 붙여넣기 해주세요!
6-
}
4+
function solution(quiz) {
5+
return quiz.map(q => {
6+
const [formula, answer] = q.split('=');
7+
return eval(formula) === +answer ? 'O' : 'X';
8+
});
9+
}
Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
//https://github.com/codeisneverodd/programmers-coding-test
22
//완벽한 정답이 아닙니다.
33
//정답 1 - codeisneverodd
4-
function solution(n) {
5-
//프로그래머스에 제출하여 통과된 함수를 복사 붙여넣기 해주세요!
6-
}
4+
function solution(lines) {
5+
const visited = lines.reduce((a, [x, y]) => {
6+
for (let i = Math.min(x, y) + 1; i <= Math.max(x, y); i++) a[i] = a[i] ? a[i] + 1 : 1;
7+
return a;
8+
}, {});
9+
10+
return Object.values(visited).filter(v => v > 1).length;
11+
}

‎level-0/다항식-더하기&120863&.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,22 @@
11
//https://github.com/codeisneverodd/programmers-coding-test
22
//완벽한 정답이 아닙니다.
33
//정답 1 - codeisneverodd
4-
function solution(n) {
5-
//프로그래머스에 제출하여 통과된 함수를 복사 붙여넣기 해주세요!
6-
}
4+
function solution(polynomial) {
5+
const countX = x => {
6+
const count = x.replaceAll('x', '');
7+
return count === '' ? 1 : +count;
8+
};
9+
10+
const count = polynomial
11+
.split(' + ')
12+
.reduce((a, c) => (c.includes('x') ? { ...a, x: a.x + countX(c) } : { ...a, num: a.num + +c }), {
13+
x: 0,
14+
num: 0,
15+
});
16+
17+
const x = count.x > 0 ? `${count.x > 1 ? count.x : ''}x` : '';
18+
const num = count.num > 0 ? '' + count.num : '';
19+
const plus = x !== '' && num !== '' ? ' + ' : '';
20+
21+
return x + plus + num;
22+
}

‎level-0/등수-매기기&120882&.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
//https://github.com/codeisneverodd/programmers-coding-test
22
//완벽한 정답이 아닙니다.
33
//정답 1 - codeisneverodd
4-
function solution(n) {
5-
//프로그래머스에 제출하여 통과된 함수를 복사 붙여넣기 해주세요!
6-
}
4+
function solution(score) {
5+
const avgs = score.map(([a, b]) => (a + b) / 2);
6+
const avgRank = [...avgs]
7+
.sort((a, b) => b - a)
8+
.map((avg, i) => ({ avg, rank: i + 1 }))
9+
.map((a, i, arr) => (i > 0 && a.avg === arr[i - 1].avg ? { ...a, rank: arr[i - 1].rank } : a));
10+
11+
return avgs.map(_avg => avgRank.find(({ avg }) => _avg === avg).rank);
12+
}
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
//https://github.com/codeisneverodd/programmers-coding-test
22
//완벽한 정답이 아닙니다.
33
//정답 1 - codeisneverodd
4-
function solution(n) {
5-
//프로그래머스에 제출하여 통과된 함수를 복사 붙여넣기 해주세요!
6-
}
4+
function solution(id_pw, db) {
5+
const [id, pw] = id_pw;
6+
if (!db.find(([_id]) => _id === id)) return 'fail';
7+
return db.find(([_id, _pw]) => _id === id && _pw === pw) ? 'login' : 'wrong pw';
8+
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//https://github.com/codeisneverodd/programmers-coding-test
22
//완벽한 정답이 아닙니다.
33
//정답 1 - codeisneverodd
4-
function solution(n) {
5-
//프로그래머스에 제출하여 통과된 함수를 복사 붙여넣기 해주세요!
6-
}
4+
function solution(my_string) {
5+
returneval(my_string);
6+
}

‎level-0/분수의-덧셈&120808&.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
//https://github.com/codeisneverodd/programmers-coding-test
22
//완벽한 정답이 아닙니다.
33
//정답 1 - codeisneverodd
4-
function solution(n) {
5-
//프로그래머스에 제출하여 통과된 함수를 복사 붙여넣기 해주세요!
6-
}
4+
function solution(denum1, num1, denum2, num2) {
5+
const denum = denum2 * num1 + denum1 * num2;
6+
const num = num1 * num2;
7+
const getGCD = (a, b) => (b === 0 ? a : getGCD(b, a % b));
8+
const gcd = getGCD(denum, num);
9+
return [denum / gcd, num / gcd];
10+
}
Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
//https://github.com/codeisneverodd/programmers-coding-test
22
//완벽한 정답이 아닙니다.
33
//정답 1 - codeisneverodd
4-
function solution(n) {
5-
//프로그래머스에 제출하여 통과된 함수를 복사 붙여넣기 해주세요!
6-
}
4+
function solution(sides) {
5+
const min = Math.min(...sides);
6+
const max1 = Math.max(...sides);
7+
const max2 = min + max1 - 1;
8+
return max2 - (max1 - min);
9+
}
10+
11+
//정답 2 - codeisneverodd
12+
function solution(sides) {
13+
return Math.min(...sides) * 2 - 1;
14+
}

‎level-0/안전지대&120866&.js

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,30 @@
11
//https://github.com/codeisneverodd/programmers-coding-test
22
//완벽한 정답이 아닙니다.
33
//정답 1 - codeisneverodd
4-
function solution(n) {
5-
//프로그래머스에 제출하여 통과된 함수를 복사 붙여넣기 해주세요!
6-
}
4+
function solution(board) {
5+
const isBombNearby = (r, c) => {
6+
const nearby = [
7+
[-1, -1],
8+
[-1, 0],
9+
[-1, 1],
10+
[0, -1],
11+
[0, 1],
12+
[1, -1],
13+
[1, 0],
14+
[1, 1],
15+
];
16+
17+
const isInBoard = (r, c) => r >= 0 && r < board.length && c >= 0 && c < board.length;
18+
19+
return nearby.some(([dR, dC]) => isInBoard(r + dR, c + dC) && board[r + dR][c + dC] === 1);
20+
};
21+
22+
let count = 0;
23+
24+
for (let r = 0; r < board.length; r++) {
25+
for (let c = 0; c < board.length; c++) {
26+
if (board[r][c] !== 1 && !isBombNearby(r, c)) count += 1;
27+
}
28+
}
29+
return count;
30+
}

‎level-0/연속된-수의-합&120923&.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
//https://github.com/codeisneverodd/programmers-coding-test
22
//완벽한 정답이 아닙니다.
33
//정답 1 - codeisneverodd
4-
function solution(n) {
5-
//프로그래머스에 제출하여 통과된 함수를 복사 붙여넣기 해주세요!
6-
}
4+
function solution(num, total) {
5+
const numArr = Array.from({ length: num }, (_, i) => i);
6+
const sum = numArr.reduce((a, c) => a + c);
7+
return numArr.map(n => n - (sum - total) / num);
8+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /