๐ JavaScript/ํ๋ก๊ทธ๋๋จธ์ค
[JS]์ฐ์ต๋ฌธ์ -x๋งํผ ๊ฐ๊ฒฉ n๊ฐ์ ์ซ์
function solution(x, n) { let answer = []; for (let i = 1; i (i + 1) * v) } map์์ ์ฒซ๋ฒ์งธ ์ธ์๋ ๋ฐฐ์ด์ value, ๋๋ฒ์งธ ์ธ์๋ ๋ฐฐ์ด์ index์์ ํ์ฉํ ํ์ด */ ํ๋ก๊ทธ๋๋จธ์ค ๋ฌธ์ ์์ฒด๋ ์ ๋ง ์ฝ์ง๋ง, map ํจ์์ 2๋ฒ์งธ ์ธ์๊ฐ ๋ฐฐ์ด์ index์์ ๊ธฐ์ตํ๊ณ ์ถํ์ ํ์ฉํ ์ ์๋๋ก ํ์
[JS] ํด์ - ์์ฃผํ์ง ๋ชปํ ์ ์
function solution(participant, completion) { let answer; participant.sort(); completion.sort(); for (let i = 0; i < participant.length; i++) { if (participant[i] !== completion[i]) { answer = participant[i]; break; } } return answer; } // ํด์ ๋ฌธ์ ๋ผ๋ ์ ์ ๊ฐ์ํ์ ๋, ์ข์ ํ์ด function solution(participant, completion) { const map = new Map(); for(let i = 0; i < participant.length; i++) { let a = participant[..
[JS]์์ ํ์-๋ชจ์๊ณ ์ฌ
function solution(answers) { const lengthAns = answers.length; const first = [1, 2, 3, 4, 5]; const second = [2, 1, 2, 3, 2, 4, 2, 5]; const third = [3, 3, 1, 1, 2, 2, 4, 4, 5, 5]; const firstAns = new Array(Math.ceil(lengthAns / first.length)) .fill(first) .flat(); const secondAns = new Array(Math.ceil(lengthAns / second.length)) .fill(second) .flat(); const thirdAns = new Array(Math.ceil(lengt..
[JS]์ํด๋ฆฌ ์ฑ๋ฆฐ์ง - ๋ถ์กฑํ ๊ธ์ก ๊ณ์ฐํ๊ธฐ
function solution(price, money, count) { let answer; let total = 0; for (let i = 1; i money) { answer = total - money; } else { return 0; } return answer; } ํ๋ก๊ทธ๋๋จธ์ค ๋ค๋ฅธ ํ์ด - ๊ฐ์ฐ์ค ๊ณต์ ์ฌ์ฉ ๋ฐ ์ผํญ์ฐ์ฐ์๋ก ๋ฆฌํด function solution(price, money, count) { const tmp = price * count * (count + 1) / 2 - money; return tmp > 0 ? tmp : 0; } ๋ค๋ฅธ ํ์ด - ใ ใ ใ ..? const solution = (..._) => Math.max(_[0]*_[2]*++_[2]/2-_[1], 0); ์ฒ์..
[JS] ์ํด๋ฆฌ ์ฑ๋ฆฐ์ง - ์ต์์ง์ฌ๊ฐํ
function solution(sizes) { let arrMax = []; let arrMin = []; for (let size of sizes) { arrMax.push(Math.max(...size)); arrMin.push(Math.min(...size)); } let answerFirst = Math.max(...arrMax); let answerSecond = Math.max(...arrMin); let answer = answerFirst * answerSecond; return answer; } ํ๋ก๊ทธ๋๋จธ์ค ํ๋ก๊ทธ๋๋จธ์ค์ ์ฅ์ ์ ๋ฌธ์ ํ์ด ํ ๋ค๋ฅธ ๋ถ๋ค์ ํ์ด๋ฅผ ๋ณผ ์ ์๋ค๋ ์ ์ด๋ค. (์ ๋ง ๊น๋ํ ์ฝ๋๋ถํฐ ๋๋ฌด ๊ธธ๊ธด ํ์ง๋ง ๊ทธ ํ๋ฆ์ด ํ๋ํ๋ ์ดํด๋๋ ์ฝ๋๊น์ง ๋ค์ํ๋ ๊ผญ ์ฐธ๊ณ ํ์) ..