diff --git a/JustDevRae/Queue/card_bundle.js b/JustDevRae/Queue/card_bundle.js new file mode 100644 index 0000000..1db6617 --- /dev/null +++ b/JustDevRae/Queue/card_bundle.js @@ -0,0 +1,15 @@ +function solution(cards1, cards2, goal) { + var answer = ""; + for (let word of goal) { + if (word == cards1[0]) { + cards1.shift(); + } else if (word == cards2[0]) { + cards2.shift(); + } else { + answer = "No"; + break; + } + } + + return (answer = "Yes"); +} diff --git a/JustDevRae/Queue/find_point_position.js b/JustDevRae/Queue/find_point_position.js new file mode 100644 index 0000000..4f16fad --- /dev/null +++ b/JustDevRae/Queue/find_point_position.js @@ -0,0 +1,10 @@ +function solution(dot) { + var answer = 0; + + if (dot[0] > 0 && dot[1] > 0) answer = 1; + if (dot[0] < 0 && dot[1] > 0) answer = 2; + if (dot[0] < 0 && dot[1] < 0) answer = 3; + if (dot[0] > 0 && dot[1] < 0) answer = 4; + + return answer; +} diff --git a/JustDevRae/Queue/login_success.js b/JustDevRae/Queue/login_success.js new file mode 100644 index 0000000..c3ccabc --- /dev/null +++ b/JustDevRae/Queue/login_success.js @@ -0,0 +1,16 @@ +function solution(id_pw, db) { + var answer = ""; + for (let i = 0; i < db.length; i++) { + if (id_pw[0] === db[i][0]) { + if (id_pw[1] === db[i][1]) { + answer = "login"; + break; + } + answer = "wrong pw"; + break; + } else { + answer = "fail"; + } + } + return answer; +} diff --git a/JustDevRae/Queue/make_hamburger.js b/JustDevRae/Queue/make_hamburger.js new file mode 100644 index 0000000..bda6c56 --- /dev/null +++ b/JustDevRae/Queue/make_hamburger.js @@ -0,0 +1,20 @@ +function solution(ingredient) { + const burger = []; + let answer = 0; + for (let i of ingredient) { + burger.push(i); + + if ( + burger.length >= 4 && + burger[burger.length - 4] === 1 && + burger[burger.length - 3] === 2 && + burger[burger.length - 2] === 3 && + burger[burger.length - 1] === 1 + ) { + burger.splice(burger.length - 4, 4); + answer++; + } + } + + return answer; +} diff --git a/JustDevRae/Queue/pair_count.js b/JustDevRae/Queue/pair_count.js new file mode 100644 index 0000000..19f39ac --- /dev/null +++ b/JustDevRae/Queue/pair_count.js @@ -0,0 +1,13 @@ +function solution(n) { + var answer = 0; + + // 1부터 n까지 숫자를 확인 + for (let i = 1; i <= n; i++) { + // i가 n의 약수인지 확인 + if (n % i === 0) { + // i가 n의 약수인지 확인 + answer++; + } + } + return answer; +} diff --git a/JustDevRae/Queue/process.js b/JustDevRae/Queue/process.js new file mode 100644 index 0000000..fcc601e --- /dev/null +++ b/JustDevRae/Queue/process.js @@ -0,0 +1,20 @@ +function solution(priorities, location) { + var answer = 0; + const queue = priorities.map((priority, index) => ({ priority, index })); + + while (queue.length > 0) { + const current = queue.shift(); + + const highPriority = queue.some((item) => item.priority > current.priority); + + if (highPriority) { + queue.push(current); + } else { + answer++; + + if (current.index === location) { + return answer; + } + } + } +} diff --git a/JustDevRae/Stack/control_Z.js b/JustDevRae/Stack/control_Z.js new file mode 100644 index 0000000..44fba87 --- /dev/null +++ b/JustDevRae/Stack/control_Z.js @@ -0,0 +1,15 @@ +function solution(s) { + var answer = 0; + let Z = 0; + const controlArray = s.split(" "); + for (let i = 0; i < controlArray.length; i++) { + if (controlArray[i] == "Z") { + answer -= Z; + continue; + } + answer += Number(controlArray[i]); + Z = Number(controlArray[i]); + } + + return answer; +} diff --git a/JustDevRae/Stack/crane_claw_game.js b/JustDevRae/Stack/crane_claw_game.js new file mode 100644 index 0000000..ab28cd5 --- /dev/null +++ b/JustDevRae/Stack/crane_claw_game.js @@ -0,0 +1,23 @@ +function solution(board, moves) { + let answer = 0; + const stack = []; + + for (let move of moves) { + for (let i = 0; i < board.length; i++) { + if (board[i][move - 1] !== 0) { + let doll = board[i][move - 1]; + board[i][move - 1] = 0; + + if (stack.length > 0 && stack[stack.length - 1] === doll) { + stack.pop(); + answer += 2; + } else { + stack.push(doll); + } + break; + } + } + } + + return answer; +} diff --git a/JustDevRae/Stack/dart_game.js b/JustDevRae/Stack/dart_game.js new file mode 100644 index 0000000..7b67c10 --- /dev/null +++ b/JustDevRae/Stack/dart_game.js @@ -0,0 +1,41 @@ +function solution(dartResult) { + var answer = 0; + const dartResultArray = dartResult.match(/\d+|[SDT]|\#|\*/g); + const stack = []; + let value; + + for (str of dartResultArray) { + if (str === "S") { + value = stack.pop(); + stack.push(value); + } else if (str === "D") { + value = stack.pop(); + stack.push(value * value); + } else if (str === "T") { + value = stack.pop(); + stack.push(value * value * value); + } else if (str === "*") { + let firtPopValue = stack.pop(); + firtPopValue *= 2; + let secondPopValue = stack.pop(); + if (secondPopValue === undefined) { + stack.push(firtPopValue); + } else { + secondPopValue *= 2; + stack.push(secondPopValue); + stack.push(firtPopValue); + } + } else if (str === "#") { + value = stack.pop(); + stack.push(value * -1); + } else { + stack.push(Number(str)); + } + } + + for (element of stack) { + answer += element; + } + + return answer; +} diff --git a/JustDevRae/Stack/reverse_string.js b/JustDevRae/Stack/reverse_string.js new file mode 100644 index 0000000..003d086 --- /dev/null +++ b/JustDevRae/Stack/reverse_string.js @@ -0,0 +1,10 @@ +function solution(my_string) { + var answer = ""; + const string = [...my_string]; + + for (let i = 0; i < my_string.length; i++) { + answer += string.pop(); + } + + return answer; +} diff --git a/JustDevRae/Stack/valid_parentheses.js b/JustDevRae/Stack/valid_parentheses.js new file mode 100644 index 0000000..14767b2 --- /dev/null +++ b/JustDevRae/Stack/valid_parentheses.js @@ -0,0 +1,16 @@ +function solution(s) { + const stack = []; + for (const c of s) { + if (c === "(") { + stack.push(c); + } else if (c === ")") { + if (stack.length === 0) { + continue; + } else { + stack.pop(); + } + } + } + + return stack.length === 0; +}