์•Œ๊ณ ๋ฆฌ์ฆ˜ & ๋ฌธ์ œํ’€์ด

Learned eval() ๋ฉ”์„œ๋“œ๋ฅผ ์•Œ๊ฒŒ๋๊ณ  ์‚ฌ์šฉํ•˜๋ฉด ์•ˆ๋˜๊ณ  ์™œ ์‚ฌ์šฉํ•˜๋ฉด ์•ˆ๋˜๋Š”์ง€ ์ˆ™์ง€ํ–ˆ๋‹ค. ํŒฉํ† ๋ฆฌ์–ผ์— ๋Œ€ํ•ด ๋ฐฐ์› ๋‹ค. ์‚ฌ์ด๋“œ ์ดํŽ™ํŠธ์— ๋Œ€ํ•ด ๋‹ค์‹œ ํ•œ๋ฒˆ ์•Œ์•˜๊ณ  ์™œ ์ง€์–‘ํ•ด์•ผํ•˜๋Š”์ง€ ์ˆ™์ง€ํ–ˆ๋‹ค. ๋ฌด์กฐ๊ฑด ํ•œ์ค„๋กœ ํ’€์–ด๋‚ด๋Š”๊ฒŒ ๊ฐ€๋…์„ฑ์— ์ข‹์ง€ ์•Š์Œ์„ ๋‹ค์‹œ ํ•œ๋ฒˆ ๋Š๊ผˆ๋‹ค. Liked ์กฐ๊ฑด์‹ ์‚ฌ์šฉ๋ฒ•์ด ์ ์  ๋‹ค์–‘ํ•ด์ง€๊ณ  ์žˆ๋‹ค. ์ƒˆ๋กœ์šด ๊ณต์‹์„ ์•Œ๊ฒŒ๋œ๊ฒŒ ๋งŽ์€ ํ•œ ์ฃผ ์˜€๋‹ค. Lacked ๋ฐ˜๋ณต๋˜๋Š” ๊ตฌ๋ฌธ์„ ์ค„์ด๋Š” ๋ฐฉ๋ฒ•์„ ์กฐ๊ธˆ ๋” ์ฐฝ์˜์ ์œผ๋กœ ์ƒ๊ฐํ•˜์ง€ ๋ชปํ–ˆ๋‹ค. ์ˆ˜ํ•™๊ณต์‹์— ๋งŽ์ด ์•ฝํ•˜๋‹ค๋Š” ๊ฑธ ๋Š๊ผˆ๋‹ค.. ํ•˜๋ฃจ ์ข…์ผ ๊ณ ๋ฏผํ–ˆ๋Š”๋ฐ ํ’€์ง€ ๋ชปํ•œ ๋ฌธ์ œ๋„ ์žˆ์—ˆ๋‹ค. (๊ตฌ์Šฌ์„ ๋‚˜๋ˆ„๋Š” ๊ฒฝ์šฐ์˜ ์ˆ˜)
function solution(emergency) { const result = []; const emergencyScoreArrray = [...emergency]; for (let i = 1; i b - a); return emergency.map(el => sortedEmergency.indexOf(el) + 1); } ์ˆœ์œ„๋Œ€๋กœ ์ •๋ ฌ๋˜์–ด ์žˆ๋Š” ๋ฐฐ์—ด์„ ํ•˜๋‚˜ ๋งŒ๋“ค๊ณ  ์›๋ณธ๋ฐฐ์—ด์„ map๋ฉ”์„œ๋“œ๋ฅผ ์ด์šฉํ•ด ์š”์†Œ๋ฅผ ์ •๋ ฌ๋˜์–ด ์žˆ๋Š” ์š”์†Œ์˜ ์ธ๋ฑ์Šค +1 ํ•˜์—ฌ ๋ฐ˜ํ™˜. 2์ค„๋กœ ๊น”๋”ํ•˜๊ฒŒ ๋๋‚˜๋‹ค๋‹ˆ ์ฐธ๊ณ ๊ฐ€ ๋งŽ์ด ๋˜์—ˆ๋‹ค!!!
function solution(common) { return common[1] - common[0] === common[2] - common[1] ? common[0] + common.length * (common[1] - common[0]) : common[common.length - 1] * 2; } ํ’€ ๋•Œ๋Š” ๋Š๋ผ์ง€ ๋ชปํ–ˆ๋Š”๋ฐ.. ๊ฐ€๋…์„ฑ์ด.. ๋ฐ˜์„ฑ.. ํ”ผ๋“œ๋ฐฑ function solution(common) { const diff1 = common[1] - common[0]; const diff2 = common[2] - common[1]; return diff1 === diff2 ? common[common.length - 1] + diff1 : common[common.length - 1] * 2; ..
function solution(n) { const result = []; primeFactorization(n, result); const set = new Set(result); return [...set]; } const primeFactorization = (num, arr) => { while (num % 2 === 0) { num = num / 2; arr.push(2); } for (let i = 3; i 2) arr.push(num); }; ์†Œ์ธ์ˆ˜๋ฅผ ๋ชจ๋‘ ๊ตฌํ•ด์„œ set์œผ๋กœ ์ค‘๋ณต์„ ์ œ๊ฑฐํ•˜๊ณ  ๋ฐฐ์—ด๋กœ ๋ณ€ํ™˜ํ•ด์„œ ์ œ์ถœ. ํ”ผ๋“œ๋ฐฑ function solution(n) { const primeSet = primeFactorization(n); return [...primeSet]; } const prim..
function solution(n, m) { const combinationArray = [BigInt(1), BigInt(1), BigInt(1)]; for (let i = BigInt(2); i
function solution(s) { const sum = s.split(" "); while (sum.includes("Z")) { const zIdx = sum.findIndex((el) => el === "Z"); sum.splice(zIdx - 1, 2); console.log(sum); } return sum.reduce((acc, cur) => acc + parseInt(cur), 0); } /* (ํ’€์ด) ๊ณต๋ฐฑ์„ ๊ธฐ์ค€์œผ๋กœ ์š”์†Œ๋ฅผ ๋‚˜๋ˆ ์ฃผ๊ณ  ๋ฐฐ์—ด์•ˆ์— 'Z'๊ฐ€ ์žˆ์„๊ฒฝ์šฐ ์›๋ณธ๋ฐฐ์—ด(sum)์—์„œ ์ด์ „ ์š”์†Œ + ํ˜„์žฌ ์š”์†Œ๋ฅผ ์ œ๊ฑฐํ•ด์ฃผ๋Š” while๋ฌธ์„ ๋Œ๋ ค์ค€ ํ›„ numberํƒ€์ž…์œผ๋กœ ๋ณ€๊ฒฝํ•˜์—ฌ ๋‚จ์€ ์š”์†Œ๋ฅผ ๋ชจ๋‘ ๋”ํ•ด์ค€ ๋’ค ๋ฐ˜ํ™˜ํ•ด์ค€๋‹ค. for๋ฌธ์œผ๋กœ ์‹œ๋„ํ•˜๋Š”๋ฐ ๊ณ„์† ์›๋ณธ๋ฐฐ์—ด์„ ๊ฑด๋“œ๋ฆฌ๋‹ˆ index๊ฐ€ ์—‰์ผœ์„œ ๊ณ ์ƒํ–ˆ๋‹ค..
function solution(my_string) { return eval(my_string); } function solution(my_string) { let result = 0; my_string = my_string.split(" ").filter((v) => v !== "+"); for (let i = 0; i < my_string.length; i++) { if (my_string[i] === "-") { result -= parseInt(my_string[i + 1] * 2); } else { result += parseInt(my_string[i]); } } return result; } /* (ํ’€์ด) 1. eval ๋ฉ”์„œ๋“œ๋ฅผ ์ด์šฉํ•ด ๋ฌธ์ž์—ด์„ ๊ณ„์‚ฐ 2. ๊ณต๋ฐฑ์œผ๋กœ ์š”์†Œ๋ฅผ ๋‚˜๋ˆ ์ฃผ๊ณ  filter..
function setSortAndFliter(arr, arr2) { return arr.sort((a, b) => a - b).filter((v) => !arr2.includes(v)); } function solution(n, lost, reserve) { const noPeClothesStudent = setSortAndFliter(lost, reserve); const extraPeClothesStudent = setSortAndFliter(reserve, lost); for (const el of noPeClothesStudent) { const extraUniformidx = extraPeClothesStudent.findIndex( (value) => value === el - 1 || va..
YunCow
'์•Œ๊ณ ๋ฆฌ์ฆ˜ & ๋ฌธ์ œํ’€์ด' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๊ธ€ ๋ชฉ๋ก