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์ค๋ก ๊น๋ํ๊ฒ ๋๋๋ค๋ ์ฐธ๊ณ ๊ฐ ๋ง์ด ๋์๋ค!!!
์๊ณ ๋ฆฌ์ฆ & ๋ฌธ์ ํ์ด/Programmers-0
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..