Skip to content

Commit cf0bad6

Browse files
authored
[yulrang] 25.01.19 (#31)
* Slice array / 기초 * Length of array items / 기초 * Shift array / 기초 * Number of duplicated item / 기초 * Remove lowest number / 중급 * Sum of matrix / 중급 * Multiple number / 중급 * Chore: 폴더명 변경경 * 문자열 뒤집기 / 기초 * 컨트롤 제트 / 기초 * 영어는 어려워 / 기초 * 문자열 계산하기 / 기초 * 크레인 인형뽑기 게임 / 중급 * refactor: 크레인 인형뽑기 게임 / 중급 * 올바른 괄호 / 중급 * 다트 게임 / 중급 * 순서쌍의 개수 / 기초 * 점의 위치 구하기 / 기초 * 로그인 성공? / 기초 * 특이한 정렬 / 기초 * 카드 뭉치 / 중급 * 공원 산책 / 중급 * 햄버거 만들기 / 중급
1 parent 2b5ed8e commit cf0bad6

File tree

7 files changed

+139
-0
lines changed

7 files changed

+139
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
function solution(n) {
2+
var answer = 0;
3+
let answerArr = [];
4+
5+
for(let i = 1; i <= n; i++) {
6+
if(n % i === 0)
7+
answerArr.push([i, n/i]);
8+
}
9+
10+
answer = answerArr.length;
11+
12+
return answer;
13+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
function solution(dot) {
2+
var answer = 0;
3+
4+
if(dot[0] > 0){
5+
answer = dot[1] > 0 ? 1 : 4;
6+
} else if(dot[0] < 0) {
7+
answer = dot[1] > 0 ? 2 : 3;
8+
}
9+
return answer;
10+
}

yulrang/03_Queue/03_Login.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
function solution(id_pw, db) {
2+
var answer = '';
3+
4+
for(const pair of db){
5+
if(pair[0] !== id_pw[0]) {
6+
answer = "fail";
7+
} else {
8+
if(pair[1] !== id_pw[1]){
9+
answer = "wrong pw";
10+
}
11+
else {
12+
answer = "login";
13+
}
14+
break;
15+
}
16+
}
17+
return answer;
18+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
function solution(numlist, n) {
2+
var answer = [];
3+
4+
answer = numlist.sort((a,b) => (Math.abs(n-a) - Math.abs(n-b)) || (b-a));
5+
6+
return answer;
7+
}

yulrang/03_Queue/05_Card_queue.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
function solution(cards1, cards2, goal) {
2+
var answer = '';
3+
4+
for(let i=0; i<goal.length; i++) {
5+
if(cards1[0] === goal[i] || cards2[0] === goal[i]){
6+
if(cards1[0] === goal[i]){
7+
cards1.shift();
8+
}
9+
if(cards2[0] === goal[i]){
10+
cards2.shift();
11+
}
12+
answer = "Yes";
13+
} else {
14+
answer = "No";
15+
break;
16+
}
17+
}
18+
19+
return answer;
20+
}

yulrang/03_Queue/06_Park_game.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
function solution(park, routes) {
2+
let pathArr = [];
3+
const WIDTH = park[0].length;
4+
const HEIGHT = park.length;
5+
6+
for(let rowIdx = 0; rowIdx < park.length; rowIdx++){
7+
const row = park[rowIdx].split("");
8+
if(row.includes("S")){
9+
const columnIdx = park[rowIdx].indexOf("S");
10+
pathArr.push([columnIdx, rowIdx]);
11+
break;
12+
}
13+
}
14+
15+
16+
for(let i = 0; i<routes.length; i++) {
17+
const DIRECTION = routes[i].split(' ')[0];
18+
const AMOUNT = Number(routes[i].split(' ')[1]);
19+
let blockPos = [-1, -1];
20+
let x = pathArr[pathArr.length-1][0];
21+
let y = pathArr[pathArr.length-1][1];
22+
23+
if (DIRECTION === "E") {
24+
blockPos = [park[y].indexOf("X", x), y];
25+
x = pathArr[pathArr.length-1][0] + AMOUNT;
26+
y = pathArr[pathArr.length-1][1];
27+
} else if (DIRECTION === "W"){
28+
blockPos = [park[y].lastIndexOf("X", x), y];
29+
x = pathArr[pathArr.length-1][0] - AMOUNT;
30+
y = pathArr[pathArr.length-1][1];
31+
} else if (DIRECTION === "S"){
32+
blockPos = [x, park.findIndex((row, idx) => idx >= y && row[x] === "X")];
33+
x = pathArr[pathArr.length-1][0];
34+
y = pathArr[pathArr.length-1][1] + AMOUNT;
35+
} else if (DIRECTION === "N"){
36+
blockPos = [x, park.slice(0, y).reverse().findIndex((row, idx) => row[x] === "X")];
37+
if (blockPos[1] !== -1) blockPos[1] = y - blockPos[1] - 1;
38+
x = pathArr[pathArr.length-1][0];
39+
y = pathArr[pathArr.length-1][1] - AMOUNT;
40+
}
41+
42+
if (x < 0 || x >= WIDTH || y < 0 || y >= HEIGHT){
43+
continue;
44+
}
45+
if(!blockPos.includes(-1)){
46+
if((y === blockPos[1] && x >= blockPos[0] && pathArr[pathArr.length > 1 ? pathArr.length-2 : 0][0] < blockPos[0]) ||
47+
(y === blockPos[1] && x <= blockPos[0] && pathArr[pathArr.length > 1 ? pathArr.length-2 : 0][0] > blockPos[0]) ||
48+
(x === blockPos[0] && y >= blockPos[1] && pathArr[pathArr.length > 1 ? pathArr.length-2 : 0][1] < blockPos[1]) ||
49+
(x === blockPos[0] && y <= blockPos[1] && pathArr[pathArr.length > 1 ? pathArr.length-2 : 0][1] > blockPos[1]) ) {
50+
continue;
51+
}
52+
}
53+
54+
pathArr.push([x, y]);
55+
}
56+
57+
return pathArr[pathArr.length-1].reverse();
58+
}
59+

yulrang/03_Queue/07_Hamberger.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
function solution(ingredient) {
2+
var answer = 0;
3+
4+
for(let i=0; i<ingredient.length; i++) {
5+
if(ingredient[i] === 1 && ingredient[i+1] === 2 && ingredient[i+2] === 3 && ingredient[i+3] === 1) {
6+
ingredient.splice(i, 4);
7+
answer++;
8+
i -= 4;
9+
}
10+
}
11+
return answer;
12+
}

0 commit comments

Comments
 (0)