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

Learned flat๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•ด๋ดค๋‹ค! ์ค‘์ฒฉ if๋ฌธ์ด ํ•„์š”ํ•˜๋‹ค ์ƒ๊ฐํ•œ ๋ถ€๋ถ„์„ ์‚ผํ•ญ์—ฐ์‚ฐ์ž๋กœ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ๋Š” ๋ฐฉ๋ฒ• Liked ๋น„๋ก ๋‚ด๊ฐ€ ์ง์ ‘ ์ƒ๊ฐํ•ด์„œ ๋งŒ๋“  ์žฌ๊ท€ํ•จ์ˆ˜๋Š” ์•„๋‹ˆ์˜€์ง€๋งŒ ๊ทธ๋ž˜๋„ ์กฐํ•ฉ ์•Œ๊ณ ๋ฆฌ์ฆ˜์— ๋Œ€ํ•ด ๋ฐฐ์šฐ๊ณ  ์‚ฌ์šฉํ–ˆ๋‹ค. ์ค„์–ด๋“  ๋ฉ”์„œ๋“œ ๊ตฌ๊ธ€๋ง Lacked const์™€ let ์œ„์น˜ ์ปจ๋ฒค์…˜ ์‹ค์ˆ˜ (const์šฐ์„  ๊ทธ๋ฆฌ๊ณ  let) ์ •๋ฆฌํ•  ๋•Œ ์‚ผํ•ญ์—ฐ์‚ฐ์ž ์ƒ๊ฐ ์•ˆ๋‚˜๋ฉด ์ค‘์ฒฉif๋ฌธ ์“ฐ๋Š” ๋ฒ„๋ฆ‡ ๋ถˆํ•„์š”ํ•œ ์ฝ”๋“œ ๋ฐ˜๋ณต
ํ’€์ด ๐Ÿ™Ž๐Ÿป‍โ™‚๏ธ function solution(participant, completion) { participant.sort(); completion.sort(); for (let i = 0; i
ํ’€์ด1 ๐Ÿ™Ž๐Ÿป‍โ™‚๏ธ //ํ’€์ด 1 function solution(nums) { const numberOfAllCases = getCombinations(nums, 3).map((innerArr) => innerArr.reduce((acc, cur) => acc + cur, 0) ); let result = 0; numberOfAllCases.map((v) => { if (primeNumber(v)) result++; }); return result; } const primeNumber = (x) => { for (let i = 2; i { const result = []; if (arrLength === 1) return arr.map((el) => [el]); arr.map((item, idx, this..
ํ’€์ด ๐Ÿ™Ž๐Ÿป‍โ™‚๏ธ function solution(answer) { const result = []; const personOne = [1, 2, 3, 4, 5]; const personTwo = [2, 1, 2, 3, 2, 4, 2, 5]; const personThree = [3, 3, 1, 1, 2, 2, 4, 4, 5, 5]; const answerOne = answer.filter((v, i) => v === personOne[i % 5]).length; const answerTwo = answer.filter((v, i) => v === personTwo[i % 8]).length; const answerThree = answer.filter((v, i) => v === personThree[i..
ํ’€์ด๐Ÿ™Ž๐Ÿป‍โ™‚๏ธ function solution(nums) { const numsSetSize = new Set(nums).size; const numsHalfCount = nums.length / 2; return numsSetSize > numsHalfCount ? numsHalfCount : numsSetSize; } /* (ํ’€์ด) ์ฃผ์–ด์ง„ ๋ฐฐ์—ด์„ Set ๊ฐ์ฒด๋กœ ๋ณ€ํ™˜ํ•˜์—ฌ ์ค‘๋ณต์„ ์ œ๊ฑฐํ•ด์ฃผ๊ณ  numsSetSize๊ฐ€ nums์˜ ๊ฐœ์ˆ˜ / 2 ๋ณด๋‹ค ๋งŽ์œผ๋ฉด nums.length์˜ ์ ˆ๋ฐ˜์ธ numsHalfCount๋ฅผ ๋ฆฌํ„ดํ•ด์ฃผ๊ณ  ์•„๋‹ˆ๋ฉด numsSetSize๋ฅผ ๋ฆฌํ„ดํ•ด์ค€๋‹ค. ์†”์งํžˆ ๋˜ ํžˆ๋“ ์ผ€์ด์Šค๊ฐ€ ์žˆ๋‹ค๋˜๊ฐ€ ํ•ด์„œ ์‹คํŒจํ•  ์ค„ ์•Œ์•˜๋Š”๋ฐ ํ†ต๊ณผ๋๋‹ค. ํ…Œ์ŠคํŠธ์˜ ์ด๋ฆ„์„ ๋ณด๋‹ˆ ํ•ด์‹œ์ธ๋ฐ ๊ด€๋ จ ์ž๋ฃŒ๋ฅผ ์ฐพ์•„๋ณด๋‹ˆ ํ•ด์‹œ๋Š” ์ž„์˜์˜ ๊ธธ์ด์˜ ๋ฐ์ดํ„ฐ๋ฅผ..
ํ’€์ด ๐Ÿ™Ž๐Ÿป‍โ™‚๏ธ function solution(sizes) { const maxSizes = Math.max(...sizes.flat()); let secondMaxSizes = 0; for (el of sizes) { if (el[0] > el[1]) { if (el[1] > secondMaxSizes) { secondMaxSizes = el[1]; } } else { if (el[0] > secondMaxSizes) { secondMaxSizes = el[0]; } } } return maxSizes * secondMaxSizes; } ๋ถˆํ•„์š”ํ•œ if ๋ฌธ์ด ๋งŽ์•„๋ณด์ธ๋‹ค.. ํ”ผ๋“œ๋ฐฑ function solution(sizes) { const maxSize = Math.max(...sizes.flat());..
์Šคํƒ (stack) ์Šคํƒ์€ ํ•œ ์ชฝ ๋์—์„œ๋งŒ ์ž๋ฃŒ๋ฅผ ๋„ฃ๊ฑฐ๋‚˜ ๋บ„ ์ˆ˜ ์žˆ๋Š” ์„ ํ˜• ๊ตฌ์กฐ(LIFO - Last In First Out)์ด๋‹ค. ๋งจ ์œ„์ชฝ ์•„์ดํ…œ์„ top์ด๋ผ ํ•œ๋‹ค. ์ž๋ฃŒ๋ฅผ ๋„ฃ๋Š”๊ฒƒ์„ push, ๋„ฃ์–ด๋‘” ์ž๋ฃŒ๋ฅผ ๊บผ๋‚ด๋Š” ๊ฒƒ์„ pop์ด๋ผ ํ•œ๋‹ค. pop์‹œ ๊บผ๋‚ด์ง€๋Š” ์ž๋ฃŒ๋Š” ๊ฐ€์žฅ ์ตœ๊ทผ์— pushํ•œ ์ž๋ฃŒ๋ถ€ํ„ฐ ๋‚˜์˜ค๊ฒŒ ๋œ๋‹ค. ๋ณดํ†ต ์Šคํƒ์€ ์œ„๊ฐ€ ๋šซ๋ฆฐ ๋น„์ปค ์ด๋ฏธ์ง€๋ฅผ ์ƒ์ƒํ•˜๋ฉด ํŽธํ•˜๋‹ค. ์Šคํƒ์ด ๊ฝ‰์ฐจ๋ฉด Stack Overflow , ๋น„์–ด์žˆ๋Š” ์ƒํƒœ๋ฅผ Underflow๋ผ ํ•œ๋‹ค.
Learned Array.from์— ๋Œ€ํ•ด ์กฐ๊ธˆ ๋” ์ดํ•ดํ–ˆ๋‹ค. ์žฌ๊ท€ํ•จ์ˆ˜์— ๋Œ€ํ•ด ๋ฐฐ์› ๋‹ค. ์ž๋ฃŒ๊ตฌ์กฐ ์Šคํƒ / ํ์— ๋Œ€ํ•ด ๋ฐฐ์› ๋‹ค. Liked ๊ตฌ๊ธ€๋ง์ด ์•„๋‹Œ ๋‚ด ๋จธ๋ฆฌ๋กœ ํ•œ์ฃผ ๋ฌธ์ œ๋ฅผ ๋‹ค ํ’€์—ˆ๋‹ค. ์Šคํƒ/ํ์— ๋Œ€ํ•ด ์ •๋ฆฌํ•˜๋ฉฐ ์ดํ•ด๋„๊ฐ€ ์˜ฌ๋ž๋‹ค. Lacked ๋ณ€์ˆ˜ ํ‚ค์›Œ๋“œ ์‹ค์ˆ˜. ๋ฌธ์ œํ’€์ด์— ๊ฑธ๋ฆฌ๋Š” ์‹œ๊ฐ„์ด ๊ธธ๋‹ค. ํ• ๊ฒŒ ๋งŽ์•„์„œ ์ •๋ฆฌ๋ฅผ ๋ฏธ๋ฃจ๊ฒŒ ๋œ๋‹ค.
YunCow
'์•Œ๊ณ ๋ฆฌ์ฆ˜ & ๋ฌธ์ œํ’€์ด' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๊ธ€ ๋ชฉ๋ก (2 Page)