Skip to content

level 0 모든 문제 풀이 #115

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

Merged
merged 3 commits into from
Oct 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions level-0/2차원으로-만들기&120842&.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//https://github.com/codeisneverodd/programmers-coding-test
//완벽한 정답이 아닙니다.
//정답 1 - codeisneverodd
function solution(num_list, n) {
let result = [];
for (let i = 0; i < num_list.length / n; i++) {
result = [...result, num_list.slice(i * n, i * n + n)];
}
return result;
}
6 changes: 6 additions & 0 deletions level-0/369게임&120891&.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//https://github.com/codeisneverodd/programmers-coding-test
//완벽한 정답이 아닙니다.
//정답 1 - codeisneverodd
function solution(order) {
return [...('' + order)].filter(num => num === '3' || num === '6' || num === '9').length;
}
6 changes: 6 additions & 0 deletions level-0/7의-개수&120912&.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//https://github.com/codeisneverodd/programmers-coding-test
//완벽한 정답이 아닙니다.
//정답 1 - codeisneverodd
function solution(array) {
return [...array.join('')].filter(a => a === '7').length;
}
7 changes: 7 additions & 0 deletions level-0/A로-B-만들기&120886&.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//https://github.com/codeisneverodd/programmers-coding-test
//완벽한 정답이 아닙니다.
//정답 1 - codeisneverodd
function solution(before, after) {
const sort = str => [...str].sort((a, b) => (a < b ? -1 : a !== b ? 1 : 0)).join('');
return sort(before) === sort(after) ? 1 : 0;
}
9 changes: 9 additions & 0 deletions level-0/OX퀴즈&120907&.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//https://github.com/codeisneverodd/programmers-coding-test
//완벽한 정답이 아닙니다.
//정답 1 - codeisneverodd
function solution(quiz) {
return quiz.map(q => {
const [formula, answer] = q.split('=');
return eval(formula) === +answer ? 'O' : 'X';
});
}
10 changes: 10 additions & 0 deletions level-0/k의-개수&120887&.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//https://github.com/codeisneverodd/programmers-coding-test
//완벽한 정답이 아닙니다.
//정답 1 - codeisneverodd
function solution(i, j, k) {
let count = 0;
for (let num = i; num <= j; num++) {
count += [...('' + num)].filter(n => +n === k).length;
}
return count;
}
6 changes: 6 additions & 0 deletions level-0/n의-배수-고르기&120905&.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//https://github.com/codeisneverodd/programmers-coding-test
//완벽한 정답이 아닙니다.
//정답 1 - codeisneverodd
function solution(n, numlist) {
return numlist.filter(num => num % n === 0);
}
7 changes: 7 additions & 0 deletions level-0/가까운-수&120890&.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//https://github.com/codeisneverodd/programmers-coding-test
//완벽한 정답이 아닙니다.
//정답 1 - codeisneverodd
function solution(array, n) {
const minDiff = Math.min(...array.map(a => Math.abs(a - n)));
return array.sort((a, b) => a - b).find(a => Math.abs(a - n) === minDiff);
}
7 changes: 7 additions & 0 deletions level-0/가위-바위-보&120839&.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//https://github.com/codeisneverodd/programmers-coding-test
//완벽한 정답이 아닙니다.
//정답 1 - codeisneverodd
function solution(rsp) {
const win = { 0: 5, 2: 0, 5: 2 };
return [...rsp].map(num => win[num]).join('');
}
7 changes: 7 additions & 0 deletions level-0/가장-큰-수-찾기&120899&.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//https://github.com/codeisneverodd/programmers-coding-test
//완벽한 정답이 아닙니다.
//정답 1 - codeisneverodd
function solution(array) {
const max = Math.max(...array);
return [max, array.indexOf(max)];
}
9 changes: 9 additions & 0 deletions level-0/각도기&120829&.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//https://github.com/codeisneverodd/programmers-coding-test
//완벽한 정답이 아닙니다.
//정답 1 - codeisneverodd
function solution(angle) {
if (angle === 180) return 4;
if (angle > 90) return 3;
if (angle === 90) return 2;
return 1;
}
9 changes: 9 additions & 0 deletions level-0/개미-군단&120837&.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//https://github.com/codeisneverodd/programmers-coding-test
//완벽한 정답이 아닙니다.
//정답 1 - codeisneverodd
function solution(hp) {
const first = Math.floor(hp / 5);
const second = Math.floor((hp - first * 5) / 3);
const third = hp - first * 5 - second * 3;
return first + second + third;
}
11 changes: 11 additions & 0 deletions level-0/겹치는-선분의-길이&120876&.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//https://github.com/codeisneverodd/programmers-coding-test
//완벽한 정답이 아닙니다.
//정답 1 - codeisneverodd
function solution(lines) {
const visited = lines.reduce((a, [x, y]) => {
for (let i = Math.min(x, y) + 1; i <= Math.max(x, y); i++) a[i] = a[i] ? a[i] + 1 : 1;
return a;
}, {});

return Object.values(visited).filter(v => v > 1).length;
}
9 changes: 9 additions & 0 deletions level-0/공-던지기&120843&.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//https://github.com/codeisneverodd/programmers-coding-test
//완벽한 정답이 아닙니다.
//정답 1 - codeisneverodd
function solution(numbers, k) {
const goNext = current => (current + 2) % numbers.length;
let current = 0;
for (let i = 0; i < k - 1; i++) current = goNext(current);
return numbers[current];
}
11 changes: 11 additions & 0 deletions level-0/구슬을-나누는-경우의-수&120840&.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//https://github.com/codeisneverodd/programmers-coding-test
//완벽한 정답이 아닙니다.
//정답 1 - codeisneverodd
function solution(balls, share) {
const [n, m] = [balls, share];
const fact = [BigInt(1), BigInt(1)];

for (let i = 2; i <= n; i++) fact[i] = fact[i - 1] * BigInt(i);

return Number(fact[n] / (fact[n - m] * fact[m]));
}
6 changes: 6 additions & 0 deletions level-0/나머지-구하기&120810&.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//https://github.com/codeisneverodd/programmers-coding-test
//완벽한 정답이 아닙니다.
//정답 1 - codeisneverodd
function solution(num1, num2) {
return num1 % num2;
}
6 changes: 6 additions & 0 deletions level-0/나이-출력&120820&.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//https://github.com/codeisneverodd/programmers-coding-test
//완벽한 정답이 아닙니다.
//정답 1 - codeisneverodd
function solution(age) {
return 2022 - age + 1;
}
9 changes: 9 additions & 0 deletions level-0/다음에-올-숫자&120924&.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//https://github.com/codeisneverodd/programmers-coding-test
//완벽한 정답이 아닙니다.
//정답 1 - codeisneverodd
function solution(common) {
const isAP = arr => arr[2] - arr[1] === arr[1] - arr[0];
return isAP(common)
? common[common.length - 1] + common[1] - common[0]
: common[common.length - 1] * (common[1] / common[0]);
}
22 changes: 22 additions & 0 deletions level-0/다항식-더하기&120863&.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//https://github.com/codeisneverodd/programmers-coding-test
//완벽한 정답이 아닙니다.
//정답 1 - codeisneverodd
function solution(polynomial) {
const countX = x => {
const count = x.replaceAll('x', '');
return count === '' ? 1 : +count;
};

const count = polynomial
.split(' + ')
.reduce((a, c) => (c.includes('x') ? { ...a, x: a.x + countX(c) } : { ...a, num: a.num + +c }), {
x: 0,
num: 0,
});

const x = count.x > 0 ? `${count.x > 1 ? count.x : ''}x` : '';
const num = count.num > 0 ? '' + count.num : '';
const plus = x !== '' && num !== '' ? ' + ' : '';

return x + plus + num;
}
6 changes: 6 additions & 0 deletions level-0/대문자와-소문자&120893&.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//https://github.com/codeisneverodd/programmers-coding-test
//완벽한 정답이 아닙니다.
//정답 1 - codeisneverodd
function solution(my_string) {
return [...my_string].map(char => (char === char.toUpperCase() ? char.toLowerCase() : char.toUpperCase())).join('');
}
6 changes: 6 additions & 0 deletions level-0/두-수의-곱&120804&.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//https://github.com/codeisneverodd/programmers-coding-test
//완벽한 정답이 아닙니다.
//정답 1 - codeisneverodd
function solution(num1, num2) {
return num1 * num2;
}
6 changes: 6 additions & 0 deletions level-0/두-수의-나눗셈&120806&.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//https://github.com/codeisneverodd/programmers-coding-test
//완벽한 정답이 아닙니다.
//정답 1 - codeisneverodd
function solution(num1, num2) {
return Math.floor((num1 / num2) * 1000);
}
6 changes: 6 additions & 0 deletions level-0/두-수의-차&120803&.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//https://github.com/codeisneverodd/programmers-coding-test
//완벽한 정답이 아닙니다.
//정답 1 - codeisneverodd
function solution(num1, num2) {
return num1 - num2;
}
6 changes: 6 additions & 0 deletions level-0/두-수의-합&120802&.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//https://github.com/codeisneverodd/programmers-coding-test
//완벽한 정답이 아닙니다.
//정답 1 - codeisneverodd
function solution(num1, num2) {
return num1 + num2
}
12 changes: 12 additions & 0 deletions level-0/등수-매기기&120882&.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//https://github.com/codeisneverodd/programmers-coding-test
//완벽한 정답이 아닙니다.
//정답 1 - codeisneverodd
function solution(score) {
const avgs = score.map(([a, b]) => (a + b) / 2);
const avgRank = [...avgs]
.sort((a, b) => b - a)
.map((avg, i) => ({ avg, rank: i + 1 }))
.map((a, i, arr) => (i > 0 && a.avg === arr[i - 1].avg ? { ...a, rank: arr[i - 1].rank } : a));

return avgs.map(_avg => avgRank.find(({ avg }) => _avg === avg).rank);
}
8 changes: 8 additions & 0 deletions level-0/로그인-성공&#63;&120883&.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//https://github.com/codeisneverodd/programmers-coding-test
//완벽한 정답이 아닙니다.
//정답 1 - codeisneverodd
function solution(id_pw, db) {
const [id, pw] = id_pw;
if (!db.find(([_id]) => _id === id)) return 'fail';
return db.find(([_id, _pw]) => _id === id && _pw === pw) ? 'login' : 'wrong pw';
}
6 changes: 6 additions & 0 deletions level-0/머쓱이보다-키-큰-사람&120585&.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//https://github.com/codeisneverodd/programmers-coding-test
//완벽한 정답이 아닙니다.
//정답 1 - codeisneverodd
function solution(array, height) {
return array.filter(a => a > height).length;
}
16 changes: 16 additions & 0 deletions level-0/모스부호-(1)&120838&.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//https://github.com/codeisneverodd/programmers-coding-test
//완벽한 정답이 아닙니다.
//정답 1 - codeisneverodd
function solution(letter) {
const morse = {
'.-':'a','-...':'b','-.-.':'c','-..':'d','.':'e','..-.':'f',
'--.':'g','....':'h','..':'i','.---':'j','-.-':'k','.-..':'l',
'--':'m','-.':'n','---':'o','.--.':'p','--.-':'q','.-.':'r',
'...':'s','-':'t','..-':'u','...-':'v','.--':'w','-..-':'x',
'-.--':'y','--..':'z'
}
return letter
.split(' ')
.map(l => morse[l])
.join('');
}
6 changes: 6 additions & 0 deletions level-0/모음-제거&120849&.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//https://github.com/codeisneverodd/programmers-coding-test
//완벽한 정답이 아닙니다.
//정답 1 - codeisneverodd
function solution(my_string) {
return my_string.replace(/[aeiou]/g, '');
}
6 changes: 6 additions & 0 deletions level-0/몫-구하기&120805&.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//https://github.com/codeisneverodd/programmers-coding-test
//완벽한 정답이 아닙니다.
//정답 1 - codeisneverodd
function solution(num1, num2) {
return Math.floor(num1 / num2);
}
6 changes: 6 additions & 0 deletions level-0/문자-반복-출력하기&120825&.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//https://github.com/codeisneverodd/programmers-coding-test
//완벽한 정답이 아닙니다.
//정답 1 - codeisneverodd
function solution(my_string, n) {
return [...my_string].map(char => char.repeat(n)).join('');
}
6 changes: 6 additions & 0 deletions level-0/문자열-계산하기&120902&.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//https://github.com/codeisneverodd/programmers-coding-test
//완벽한 정답이 아닙니다.
//정답 1 - codeisneverodd
function solution(my_string) {
return eval(my_string);
}
6 changes: 6 additions & 0 deletions level-0/문자열-뒤집기&120822&.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//https://github.com/codeisneverodd/programmers-coding-test
//완벽한 정답이 아닙니다.
//정답 1 - codeisneverodd
function solution(my_string) {
return [...my_string].reverse().join('');
}
12 changes: 12 additions & 0 deletions level-0/문자열-밀기&120921&.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//https://github.com/codeisneverodd/programmers-coding-test
//완벽한 정답이 아닙니다.
//정답 1 - codeisneverodd
function solution(A, B) {
const pushRight = str => [str[str.length - 1], ...str.slice(0, str.length - 1)].join('');
for (let i = 0; i <= A.length; i++) {
if (A === B) return i;
A = pushRight(A);
}

return -1;
}
9 changes: 9 additions & 0 deletions level-0/문자열-정렬하기-(1)&120850&.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//https://github.com/codeisneverodd/programmers-coding-test
//완벽한 정답이 아닙니다.
//정답 1 - codeisneverodd
function solution(my_string) {
return my_string
.match(/[0-9]/g)
.map(str => +str)
.sort((a, b) => a - b);
}
9 changes: 9 additions & 0 deletions level-0/문자열-정렬하기-(2)&120911&.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//https://github.com/codeisneverodd/programmers-coding-test
//완벽한 정답이 아닙니다.
//정답 1 - codeisneverodd
function solution(my_string) {
return [...my_string]
.map(char => char.toLowerCase())
.sort((a, b) => (a < b ? -1 : a > b ? 1 : 0))
.join('');
}
6 changes: 6 additions & 0 deletions level-0/문자열안에-문자열&120908&.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//https://github.com/codeisneverodd/programmers-coding-test
//완벽한 정답이 아닙니다.
//정답 1 - codeisneverodd
function solution(str1, str2) {
return str1.includes(str2) ? 1 : 2;
}
6 changes: 6 additions & 0 deletions level-0/배열-두-배-만들기&120809&.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//https://github.com/codeisneverodd/programmers-coding-test
//완벽한 정답이 아닙니다.
//정답 1 - codeisneverodd
function solution(numbers) {
return numbers.map(n => n * 2);
}
6 changes: 6 additions & 0 deletions level-0/배열-뒤집기&120821&.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//https://github.com/codeisneverodd/programmers-coding-test
//완벽한 정답이 아닙니다.
//정답 1 - codeisneverodd
function solution(num_list) {
return num_list.reverse();
}
6 changes: 6 additions & 0 deletions level-0/배열-원소의-길이&120854&.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//https://github.com/codeisneverodd/programmers-coding-test
//완벽한 정답이 아닙니다.
//정답 1 - codeisneverodd
function solution(strlist) {
return strlist.map(s => s.length);
}
6 changes: 6 additions & 0 deletions level-0/배열-자르기&120833&.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//https://github.com/codeisneverodd/programmers-coding-test
//완벽한 정답이 아닙니다.
//정답 1 - codeisneverodd
function solution(numbers, num1, num2) {
return numbers.slice(num1, num2 + 1);
}
8 changes: 8 additions & 0 deletions level-0/배열-회전시키기&120844&.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//https://github.com/codeisneverodd/programmers-coding-test
//완벽한 정답이 아닙니다.
//정답 1 - codeisneverodd
function solution(numbers, direction) {
return direction === 'right'
? [numbers[numbers.length - 1], ...numbers.slice(0, numbers.length - 1)]
: [...numbers.slice(1), numbers[0]];
}
6 changes: 6 additions & 0 deletions level-0/배열의-유사도&120903&.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//https://github.com/codeisneverodd/programmers-coding-test
//완벽한 정답이 아닙니다.
//정답 1 - codeisneverodd
function solution(s1, s2) {
return s1.filter(s => s2.includes(s)).length;
}
6 changes: 6 additions & 0 deletions level-0/배열의-평균값&120817&.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//https://github.com/codeisneverodd/programmers-coding-test
//완벽한 정답이 아닙니다.
//정답 1 - codeisneverodd
function solution(numbers) {
return numbers.reduce((a, c) => a + c, 0) / numbers.length;
}
Loading