Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add (programmers 코딩테스트 입문 Day 23): js 풀이
- Loading branch information
Showing
4 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |