๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

๋ถ„๋ฅ˜ ์ „์ฒด๋ณด๊ธฐ

(230)
[์•Œ๊ณ ๋ฆฌ์ฆ˜ || ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] ์‹คํŒจ์œจ ํ‘ธ๋Š”๋ฐ ์‹œ๊ฐ„ ์ข€ ๊ฑธ๋ฆฌ๊ธด ํ–ˆ๋Š”๋ฐ, ๊ทธ๋ž˜๋„ ํ˜ผ์ž ํž˜์œผ๋กœ ํ’€์–ด๋ƒˆ๋‹ค. ๋‚˜ ์ž์‹  ๋Œ€๊ฒฌํ•ด! ์ฒ˜์Œ์— ์—„์ฒญ ๋ณต์žกํ•˜๊ฒŒ ์ƒ๊ฐํ–ˆ๋‹ค. (์ฑŒ๋ฆฐ์ง€ ํ•˜๋Š” ์‚ฌ๋žŒ ์ˆ˜๋ฅผ ๋”ฐ๋กœ ๋‹ด๊ณ , ํ†ตํ™”ํ•œ ์‚ฌ๋žŒ ์ˆ˜๋ฅผ ๋”ฐ๋กœ ๋‹ด๊ณ ..) function solution(N, stages) { let passPeople = {}; let challengePeople = {}; for (let i = 1; i { if (i i) passPeople[i] += 1; if (stage >= i) challengePeople[i] += 1; } else { if (stage >= i) passPeople[i - 1] += 1; if (stage >= i) challengePeople[i - 1] += 1; } }) } let failRate = {}; for (le..
[์•Œ๊ณ ๋ฆฌ์ฆ˜ || ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] ์นด๋“œ ๋ญ‰์น˜ function solution(cards1, cards2, goal) { let rmCount = 0; goal.map((word) => { if (cards1[0] === word) { rmCount += 1; cards1.splice(0, 1); } else if (cards2[0] === word) { rmCount += 1; cards2.splice(0, 1); } else { return; } }) return rmCount === goal.length ? "Yes" : "No" } ์ฒจ์— ์ด ์กฐ๊ฑด์ด ์žˆ๋Š” ์ค„ ๋ชจ๋ฅด๊ณ , cards1, 2 ์˜ length๊ฐ€ 0 ์ด๋ฉด yes ๋ฅผ return ํ–ˆ๋‹ค. ์•„๋ž˜๋Š” ๋น„๋‚œ๋‹˜์ด ์œ„์˜ ์ฝ”๋“œ๋ฅผ ์ค‘์š”๋„์— ๋”ฐ๋ผ ๋ฐ˜๋ณต๋ฌธ์„ ์—†์• ๋Š” ๋ฐฉ๋ฒ•์œผ๋กœ ์ œ์•ˆํ•ด์ฃผ์‹  ์ฝ”๋“œ function so..
[์•Œ๊ณ ๋ฆฌ์ฆ˜ || ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] ๋‘ ์ˆ˜์˜ ํ•ฉ - BigInt ๊ณ„์‚ฐ BigInt ๋Š” BigInt ๋ฒ”์œ„ ๋‚ด์—์„œ๋งŒ ๊ณ„์‚ฐํ•ด์•ผํ•˜๋‚˜ ํ—ท๊ฐˆ๋ ค์„œ ์ฒ˜์Œ์—” ์ด๋ ‡๊ฒŒ ํ’€์—ˆ๋‹ค. function solution(a, b) { const bigInt = Number.MAX_SAFE_INTEGER; if (a bigInt) { return BigInt(a) + BigInt(b)+''; } } ๊ทผ๋ฐ bigInt ๋Š” Number.MAX_SAFE_INTEGER // 9007199254740991 Number ์˜ ๊ฐ€์žฅ ํฐ ๋ฒ”์œ„๋ณด๋‹ค ํฐ ์ˆ˜๋ฅผ ๊ณ„์‚ฐํ•  ์ˆ˜ ์žˆ๋Š” ๊ฑฐ๊ณ , ๊ทธ ์•„๋ž˜ ๋ฒ”์œ„์ธ ์ผ๋ฐ˜ ์ •์ˆ˜์˜ ๋ฒ”์œ„๋„ ์—ฐ์‚ฐ์ด ๊ฐ€๋Šฅํ–ˆ๋‹ค. ๊ทธ๋ž˜์„œ ์•„๋ž˜์ฒ˜๋Ÿผ BigInt ๊ฐ€ ํ•ด๋‹นํ•˜๋Š”์ง€ ์•„๋‹Œ์ง€์— ์ƒ๊ด€์—†์ด ๋”ํ•ด์ฃผ๋ฉด ๋œ๋‹ค. String ์œผ๋กœ return ํ•ด์•ผํ•˜๋‹ˆ, + '' ์„ ๋ถ™์˜€๋‹ค. function solution(a, b) { ret..
[์•Œ๊ณ ๋ฆฌ์ฆ˜ || ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] ๐Ÿ”์†Œ์ˆ˜ ์ฐพ๊ธฐ ์˜ค๋Š˜์€ ์‹œ๊ฐ„์˜ ํ•œ๊ณ„๋ฅผ ๋ชป๋„˜์–ด์„œ ๋น„๋‚œ๋‹˜์˜ ์ฝ”๋“œ๋ฅผ ๋ณด๊ณ  ๊ณต๋ถ€ํ•˜๋Š” ์‹œ๊ฐ„์œผ๋กœ ๋Œ€์ฒดํ–ˆ๋‹ค. ์ฒ˜์Œ์—” for ๋ฌธ์œผ๋กœ 1, 2, ๋ฅผ ์ œ์™ธํ•œ ์ดํ›„์˜ ์ˆซ์ž๋ถ€ํ„ฐ ์•ฝ์ˆ˜์˜ ๊ฐœ์ˆ˜๋ฅผ ์„ธ์–ด๋ณด๊ณ  ์†Œ์ˆ˜์ธ์ง€ ์•„๋‹Œ์ง€ ํŒ๋ณ„ํ•˜๋Š” ๋ฐฉ์‹์œผ๋กœ ํ’€์—ˆ๋Š”๋ฐ, ๋ฒ”์œ„๊ฐ€ ๋„ˆ๋ฌด ๋งŽ์•˜๋Š”์ง€ ์‹œ๊ฐ„์ดˆ๊ณผ๋กœ ํ†ต๊ณผ๋˜์ง€ ๋ชปํ–ˆ๋‹ค. ์ด๋ ‡๊ฒŒ ์ œ๊ณฑ๊ทผ์„ ์ด์šฉํ•˜๋ฉด ํ›จ์”ฌ ๋” ์ ์€ ๋ฒ”์œ„ ๋‚ด์—์„œ ์•ฝ์ˆ˜๋ฅผ ๊ตฌํ•  ์ˆ˜ ์žˆ๋‹ค. ์–ด์ฐจํ”ผ ์•ฝ์ˆ˜๋Š” ๋‘ ์ˆ˜์˜ ๊ณฑ์œผ๋กœ ์ด๋ค„์ง€๊ธฐ ๋•Œ๋ฌธ์— 16์˜ ์•ฝ์ˆ˜์ธ 2๋ฅผ ๊ตฌํ–ˆ๋‹ค๋ฉด ์ž๋™์œผ๋กœ 8๋„ ์กด์žฌํ•˜๋Š” ๊ฒƒ์ด๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค. ๋น„๋‚œ๋‹˜์˜ ์ฝ”๋“œ๋ฅผ ๋ณด๋ฉด ์†Œ์ˆ˜๋ฅผ ๊ตฌํ•œ๋‹ค๊ธฐ ๋ณด๋‹จ, ์†Œ์ˆ˜๊ฐ€ ์•„๋‹Œ ์ˆ˜๋ฅผ ์†Œ๊ฑฐํ•ด์ฃผ๋Š” ๋ฐฉ์‹์„ ์ฑ„ํƒํ•˜๊ณ  ์žˆ๋‹ค. function solution(n) { let isPrime = new Array(n + 1).fill(true).fill(false, 0, 2) for (let i..
[์•Œ๊ณ ๋ฆฌ์ฆ˜ || ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] ์†Œ์ˆ˜ ๋งŒ๋“ค๊ธฐ - ์ค‘๋ณต๋˜์ง€ ์•Š๊ฒŒ ์ผ์ •ํ•œ ๊ฐœ์ˆ˜์˜ ์š”์†Œ ๋ฝ‘๊ธฐ ๊ฒฝ์šฐ์˜ ์ˆ˜๋ฅผ ๋ชจ๋‘ ์•Œ์•„์•ผ ํ•œ๋‹ค๋Š”๊ฒŒ ์ฐธ ๊ณจ์น˜๊ฐ€ ์•„ํŒ ๋‹ค. ์™œ๋ƒ๋ฉด ๊ทธ๋Ÿด์‹ธํ•œ ๋ฐฉ๋ฒ•์ด ์žˆ์„๊ฑฐ ๊ฐ™์•„์„œ ๊ทธ๋žฌ๋Š”๋ฐ, ์‚ฌ์‹ค ๋ณ„ ๋ฐฉ๋ฒ•์€ ์—†์—ˆ์Œ. ^_^ ๊ฑ for ๋ฌธ์œผ๋กœ ์•ˆ๊ฒน์น˜๊ฒŒ ๋Œ๋ฆฌ๋Š” ์ˆ˜ ๋ฐ–์—!! function solution(nums) { const isPr = (num) => { if (num % 2 === 0) return; let m = []; for (let i = 1; i < num; i++) { num % i === 0 && m.push(i) } return m.length === 1 ? true : false; } let count = 0; for (let i = 0; i < nums.length; i++) { for (let j = i + 1; j < nums.length; j++) { for (let..
[์•Œ๊ณ ๋ฆฌ์ฆ˜ || ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] ๋ฆฌ์ŠคํŠธ ์ž๋ฅด๊ธฐ ๋ฌธ์ œ๋ฅผ ์ฝ๊ณ ๋‚˜์„œ ์ด๊ฑฐ์Šจ switch ๋ฌธ์„ ์“ฐ๊ธฐ ๋”ฑ ์ข‹๋‹ค! ๋ผ๊ณ  ์ƒ๊ฐํ•จ. function solution(n, slicer, num_list) { let result = []; switch (n) { case 1: result = num_list.slice(0, slicer[1] + 1); break; case 2: result = num_list.slice(slicer[0]); break; case 3: result = num_list.slice(slicer[0], slicer[1] + 1); break; case 4: result = num_list.slice(slicer[0], slicer[1] + 1).filter((v, i) => i % slicer[2] === 0); } return(result..
[์•Œ๊ณ ๋ฆฌ์ฆ˜ || ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] ๋ฌธ์ž์—ด ๋ฌถ๊ธฐ function solution(strArr) { let lengthArr = new Array(30).fill(0); strArr.map(v => lengthArr[v.length - 1] += 1) return Math.max(...lengthArr); } ์ฃผ์–ด์ง€๋Š” ์›์†Œ์˜ ๊ธธ์ด๋Š” ์ตœ๋Œ€๊ฐ€ 30์ด๊ธฐ ๋•Œ๋ฌธ์— 30๊ฐœ์˜ ์ž๋ฆฌ๋ฅผ ๊ฐ€์ง„ ๋ฐฐ์—ด์„ ๋จผ์ € ๋งŒ๋“ ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ์ฃผ์–ด์ง„ strarr ์˜ ์›์†Œ์˜ ๊ธธ์ด-1 ํ•œ index ์— +1์„ ํ•ด์ค€๋‹ค. ์ฒ˜์Œ์— fill(0) ์œผ๋กœ ์ˆซ์ž๋ฅผ ๋„ฃ์–ด์ฃผ์ง€ ์•Š์œผ๋ฉด undefined ์— +1 ์„ ํ•ด์ฃผ๋Š” ๊ฑฐ๋‚˜ ๋งˆ์ฐฌ๊ฐ€์ง€๋ผ์„œ ๊ผญ 0์„ ๋„ฃ์–ด์ค€๋‹ค. map ์—ฐ์‚ฐ์ด ๋๋‚œ ํ›„ lengthArr ์—์„œ ๊ฐ€์žฅ ํฐ ์ˆ˜๋ฅผ return ํ•ด์ค€๋‹ค.
[์•Œ๊ณ ๋ฆฌ์ฆ˜ || ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] ์ปคํ”ผ ์‹ฌ๋ถ€๋ฆ„ ๋ผ๋–ผ๊ฐ€ ํฌํ•จ๋˜์ง€ ์•Š์€ ๋ฌธ์ž์—ด์˜ ๊ฒฝ์šฐ์—” ์ „๋ถ€ 4500์›์ด๋‹ˆ, cafelatte ํ•˜๋Š” ๋‹จ์–ด๊ฐ€ ํฌํ•จ๋˜์–ด์žˆ๋Š”์ง€๋ฅผ ํ™•์ธํ•˜๊ณ  ๊ฐ’์„ ๋”ํ•ด์ฃผ๋ฉด ๋œ๋‹ค. function solution(order) { return order.reduce((acc, choice) => choice.includes("cafelatte") ? acc + 5000 : acc + 4500, 0); }

728x90
๋ฐ˜์‘ํ˜•