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

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..
YunCow
'์•Œ๊ณ ๋ฆฌ์ฆ˜ & ๋ฌธ์ œํ’€์ด/Programmers-0' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๊ธ€ ๋ชฉ๋ก