diff --git "a/yujin-level0/Week23/\354\244\221\354\225\231\352\260\222_\352\265\254\355\225\230\352\270\260.js" "b/yujin-level0/Week23/\354\244\221\354\225\231\352\260\222_\352\265\254\355\225\230\352\270\260.js" new file mode 100644 index 0000000..2cc43f7 --- /dev/null +++ "b/yujin-level0/Week23/\354\244\221\354\225\231\352\260\222_\352\265\254\355\225\230\352\270\260.js" @@ -0,0 +1,15 @@ +function solution(array) { + // 배열 길이 중 중앙값 (중간 index) 찾기 + const mid_num = Math.floor(array.length / 2); + + // 오름차순으로 정렬하기 - sort() 메서드 사용 + const asc_array = array.sort((a, b) => a - b); + + // 오름차순된 새로운 배열 중 중간 index 반환하기 + return asc_array[mid_num]; +} + +// 다른 풀이 +// function solution(array) { +// return array.sort((a, b) => a - b)[Math.floor(array.length / 2)]; +// } diff --git "a/yujin-level0/Week23/\354\247\235\354\210\230\353\212\224_\354\213\253\354\226\264\354\232\224.js" "b/yujin-level0/Week23/\354\247\235\354\210\230\353\212\224_\354\213\253\354\226\264\354\232\224.js" new file mode 100644 index 0000000..7572ce8 --- /dev/null +++ "b/yujin-level0/Week23/\354\247\235\354\210\230\353\212\224_\354\213\253\354\226\264\354\232\224.js" @@ -0,0 +1,18 @@ +function solution(n) { + var answer = []; + + for (let i = 1; i <= n; i++) { + if (i % 2 != 0) { + answer.push(i); + } + } + + return answer; +} + +// 다른 풀이 +// function solution(n) { +// var answer = []; +// for (let i = 1; i<=n; i+=2) answer.push(i) +// return answer; +// } diff --git "a/yujin-level0/Week24/\352\260\234\353\257\270_\352\265\260\353\213\250.js" "b/yujin-level0/Week24/\352\260\234\353\257\270_\352\265\260\353\213\250.js" new file mode 100644 index 0000000..4177730 --- /dev/null +++ "b/yujin-level0/Week24/\352\260\234\353\257\270_\352\265\260\353\213\250.js" @@ -0,0 +1,11 @@ +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; +} + +// 다른 풀이 +// function solution(hp) { +// return Math.floor(hp/5)+Math.floor((hp%5)/3)+(hp%5)%3; +// } diff --git "a/yujin-level0/Week24/\354\233\203\352\270\260\352\262\214_\355\225\240\354\235\270_\353\260\233\352\270\260.js" "b/yujin-level0/Week24/\354\233\203\352\270\260\352\262\214_\355\225\240\354\235\270_\353\260\233\352\270\260.js" new file mode 100644 index 0000000..c138b78 --- /dev/null +++ "b/yujin-level0/Week24/\354\233\203\352\270\260\352\262\214_\355\225\240\354\235\270_\353\260\233\352\270\260.js" @@ -0,0 +1,15 @@ +function solution(price) { + if (price >= 500000) { + return Math.floor(price * 0.8); + } else if (price >= 300000) { + return Math.floor(price * 0.9); + } else if (price >= 100000) { + return Math.floor(price * 0.95); + } else return price; +} + +// 다른 풀이 +// function solution(price) { +// price = price>=500000?price*0.8:price>=300000?price*0.9:price>=100000?price*0.95:price; +// return ~~(price); +// } diff --git "a/yujin-level0/Week25/\352\260\200\354\234\204 \353\260\224\354\234\204 \353\263\264.js" "b/yujin-level0/Week25/\352\260\200\354\234\204 \353\260\224\354\234\204 \353\263\264.js" new file mode 100644 index 0000000..b6b8567 --- /dev/null +++ "b/yujin-level0/Week25/\352\260\200\354\234\204 \353\260\224\354\234\204 \353\263\264.js" @@ -0,0 +1,27 @@ +function solution(rsp) { + let result = ""; + for (let i = 0; i < rsp.length; i++) { + if (rsp[i] === "2") { + result += "0"; + } else if (rsp[i] === "0") { + result += "5"; + } else if (rsp[i] === "5") { + result += "2"; + } + } + return result; +} + +// 다른 풀이 +/* + 가위는 2 바위는 0 보는 5 +*/ +// function solution(rsp) { +// let arr = { +// 2: 0, +// 0: 5, +// 5: 2 +// }; +// var answer = [...rsp].map(v => arr[v]).join(""); +// return answer; +// } diff --git "a/yujin-level0/Week25/\354\243\274\354\202\254\354\234\204\354\235\230 \352\260\234\354\210\230.js" "b/yujin-level0/Week25/\354\243\274\354\202\254\354\234\204\354\235\230 \352\260\234\354\210\230.js" new file mode 100644 index 0000000..cb53c96 --- /dev/null +++ "b/yujin-level0/Week25/\354\243\274\354\202\254\354\234\204\354\235\230 \352\260\234\354\210\230.js" @@ -0,0 +1,15 @@ +function solution(box, n) { + return parseInt(box[0] / n) * parseInt(box[1] / n) * parseInt(box[2] / n); +} + +// 다른 풀이 +// function solution(box, n) { +// let [width, length, height] = box; + +// return Math.floor(width / n) * Math.floor(length / n) * Math.floor(height / n); +// } + +// 다른 풀이 2 +// function solution(box, n) { +// return box.reduce((acc,v) => acc * Math.floor(v / n), 1); +// }