Skip to content

Commit

Permalink
add (programmers 코딩테스트 입문 Day 23): js 풀이
Browse files Browse the repository at this point in the history
  • Loading branch information
padosum committed Nov 18, 2022
1 parent 7ab2019 commit 19e0bea
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 0 deletions.
10 changes: 10 additions & 0 deletions programmers/level0/등수 매기기.js
@@ -0,0 +1,10 @@
function solution(score) {
const average = score.map(value => {
const [eng, math] = value;
return (eng + math) / 2;
});

const sorted = [...average].sort((a, b) => b - a);

return average.map(avg => sorted.findIndex(v => v === avg) + 1);
}
12 changes: 12 additions & 0 deletions programmers/level0/로그인 성공?.js
@@ -0,0 +1,12 @@
function solution(id_pw, db) {
const [id, pw] = id_pw;
if (db.some(([db_id, db_pw]) => db_id === id && db_pw === pw)) {
return 'login';
}

if (db.some(([db_id, db_pw]) => db_id === id && db_pw !== pw)) {
return 'wrong pw';
}

return 'fail';
}
16 changes: 16 additions & 0 deletions programmers/level0/옹알이 (1).js
@@ -0,0 +1,16 @@
function solution(babbling) {
const pronounces = ['aya', 'ye', 'woo', 'ma'];

const result = babbling
.map(word => {
let remainWord = word;
for (pronounce of pronounces) {
remainWord = remainWord.replace(new RegExp(`(${pronounce})`, 'g'), ' ');
}

return remainWord;
})
.filter(word => word.trim() === '').length;

return result;
}
17 changes: 17 additions & 0 deletions programmers/level0/특이한 정렬.js
@@ -0,0 +1,17 @@
function solution(numlist, n) {
numlist.sort((a, b) => {
if (Math.abs(a - n) > Math.abs(b - n)) {
return 1;
} else if (Math.abs(a - n) < Math.abs(b - n)) {
return -1;
} else if (Math.abs(a - n) === Math.abs(b - n)) {
if (a - b > 0) {
return -1;
} else {
return 1;
}
}
});

return numlist;
}

0 comments on commit 19e0bea

Please sign in to comment.