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

๋ฌธ์ œ ๋‚ด์šฉ ํ’€์ด๐Ÿ™‍โ™‚๏ธ function solution(numbers) { const emptyArray = []; const numCount = numbers.length; for (let i = 0; i a - b); const result = sortedArray.filter( (value, idx) => sortedArray.indexOf(value) === idx ); return result; } /* (ํ’€์ด) ์ด๋ฒˆ ํ’€์ด๋Š” ๊ฒฐ..
๋ฌธ์ œ๋‚ด์šฉ ํ’€์ด ๐Ÿ™‍โ™‚๏ธ function solution(strings, n) { strings.sort((secondArg, firstArg) => { if (secondArg[n] ํฐ์ˆ˜)์ด๋ฏ€๋กœ firstArg[n] ์ด secondArg[n] ๋ณด๋‹ค ํด ๊ฒฝ์šฐ ๋ฐฐ์—ด์˜ ์œ„์น˜๋ฅผ ๋ณ€๊ฒฝํ•˜๋„๋ก -1์„ ๋ฐ˜ํ™˜ํ•˜๊ณ  ๋‘˜์˜ ๊ฐ’์ด ๋™์ผํ•  ๊ฒฝ์šฐ if๋ฌธ์„ ํ•œ๋ฒˆ ๋” ์‚ฌ์šฉํ•˜์—ฌ ๋ฌธ์ž์—ด ..
๋ฌธ์ œ๋‚ด์šฉ ํ’€์ด ๐Ÿ™‍โ™‚๏ธ function solution(n) { for (i = 2; i < n; i++) { if (n % i === 1) return i; } } /* (ํ’€์ด) n์˜ ์ œํ•œ์‚ฌํ•ญ์€ 3~1,000,000์ด๋ฏ€๋กœ i๋ฅผ 2๋ถ€ํ„ฐ ์‹œ์ž‘ํ•ด์„œ for๋ฌธ์„ ๋Œ๋ฆฌ๊ณ  ๋‚˜๋จธ์ง€๊ฐ€ 1์ด๋˜๋Š”๊ฒฝ์šฐ๊ฐ€ ๋‚˜์˜ค๋ฉด ๋ฐ”๋กœ i๋ฅผ return ํ•˜๊ณ  ๋ฐ˜๋ณต๋ฌธ์„ ์ข…๋ฃŒํ•œ๋‹ค. ๋‚˜๋จธ์ง€๊ฐ€ 1์ด ๋˜๋Š” ์ž์—ฐ์ˆ˜ x ๋ฅผ ๋‹ค๋ฅธ ๋ฐฉ๋ฒ•์œผ๋กœ ํ• ์ˆ˜๋Š” ์—†์„๊นŒ ๊ณ ๋ฏผํ•ด ๋ดค๋Š”๋ฐ ์ฐพ์ง€ ๋ชปํ–ˆ๋‹ค๐Ÿค” */ ํ‘ธ๋Š” ๋ฐฉ์‹ ์ž์ฒด๋Š” ๊ดœ์ฐฎ๊ฒŒ ์ž˜ ํ’€์—ˆ์ง€๋งŒ for๋ฌธ์˜ ๋ณ€์ˆ˜ i์— let,var ๋“ฑ ๋ณ€์ˆ˜ํ‚ค์›Œ๋“œ๋ฅผ ๋‹ฌ์•„์ค˜์•ผ ํ•˜๋Š” ์ด์œ ๋ฅผ ๋ชฐ๋ž๋Š”๋ฐ ์ด๋ฒˆ์— ์•Œ๊ฒŒ๋์œผ๋‹ˆ ๊ธฐ๋กํ•ด๋ณด์ž. for๋ฌธ์—์„œ let์„ ์จ์ค˜์•ผ ํ•˜๋Š” ์ด์œ  var : ์žฌ์„ ์–ธ ๊ฐ€๋Šฅ, ์žฌํ• ๋‹น ๊ฐ€๋Šฅ ( ํ•จ์ˆ˜ ๋ ˆ๋ฒจ ์Šค์ฝ”ํ”„ ) let : ์žฌ์„ ์–ธ ๋ถˆ๊ฐ€..
๋ฌธ์ œ๋‚ด์šฉ ์„œ์šธ์—์„œ ๊น€์„œ๋ฐฉ ์ฐพ๊ธฐ ํ’€์ด ๐Ÿ™‍โ™‚๏ธ function solution(seoul) { return `๊น€์„œ๋ฐฉ์€ ${seoul.indexOf("Kim")}์— ์žˆ๋‹ค`; } /* (ํ’€์ด) indexOf ๋ช…๋ น์–ด๋กœ Kim ์„ ์ฐพ์•„ ํ…œํ”Œ๋ฆฟ๋ฆฌํ„ฐ๋Ÿด์„ ์ด์šฉํ•ด ๋ฐ”๋กœ ๋ฆฌํ„ดํ•ด์คฌ๋‹ค. indexOf๋„ O(n)์˜ ์‹œ๊ฐ„๋ณต์žก๋„๋ฅผ ๊ฐ€์ง€๋ฉฐ for๋ฌธ๊ณผ ๋™์ผํ•˜๊ณ  for๋ฌธ์—์„œ break์„ ์ด์šฉํ•ด ๊ฒฐ๊ณผ๋ฅผ ์ฐพ์œผ๋ฉด ๋ฐ”๋กœ ๋น ์ ธ๋‚˜์˜ค๋Š” ๊ฒƒ๊ณผ ๋™์ผํ•˜๊ธฐ์— ๊ฐ€๋…์„ฑ์ด ์ข‹์€ indexOf๋ฅผ ์‚ฌ์šฉํ–ˆ๋‹ค. */ ํ•œ์ค„๋กœ ์ž˜ ํ’€์–ด๋‚ธ๊ฒƒ ๊ฐ™๋‹ค ๋งŒ์กฑ๐Ÿ’ช ๋ฌธ์ œ๋‚ด์šฉ ์ˆ˜๋ฐ•์ˆ˜๋ฐ•์ˆ˜๋ฐ•์ˆ˜๋ฐ•์ˆ˜ ํ’€์ด ๐Ÿ™‍โ™‚๏ธ function solution(n) { return n % 2 === 0 ? "์ˆ˜๋ฐ•".repeat(n / 2) : "์ˆ˜๋ฐ•".repeat(n / 2) + "์ˆ˜"; } /* (ํ’€์ด) ..
๋ฌธ์ œ ๋‚ด์šฉ 3์ง„๋ฒ•์ด๋ž€? ๐Ÿค” ์‚ฌ๋žŒ์ด ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์€ 10์ง„๋ฒ•, ์ปดํ“จํ„ฐ์—์„œ๋Š” 2์ง„๋ฒ•์„ ์‚ฌ์šฉํ•œ๋‹ค. 3์ง„๋ฒ•์„ ์‚ฌ์šฉํ•˜๋Š” ๊ณณ์— ๋Œ€ํ•ด ์ฐพ์•„๋ดค๋Š”๋ฐ ๋”ฑํžˆ ์ •๋ณด๊ฐ€ ์—†๋Š”๊ฑฐ๊ฐ™๋‹ค. ์• ์ดˆ์— ์ด ํ’€์ด๋Š” 3์ง„๋ฒ• ๋ฟ๋งŒ ์•„๋‹ˆ๋ผ ์ง„๋ฒ•์˜ ๋ณ€๊ฒฝ์ด ๊ฐ€๋Šฅํ•œ ๊ฒƒ์ด๊ธฐ์— ํ•„์š”์— ๋”ฐ๋ผ ์‚ฌ์šฉํ•˜๋ฉด ๋ ๊ฑฐ๊ฐ™๋‹ค. ํ’€์ด ๐Ÿ™‍โ™‚๏ธ function solution(n) { const convertNumber = n.toString(3).split("").reverse().join(""); const againConvertNumber = parseInt(convertNumber, 3); return againConvertNumber; } /* (ํ’€์ด) ์ฃผ์–ด์ง„ n ์„ toString์œผ๋กœ 3์ง„๋ฒ•์œผ๋กœ ๋ณ€๊ฒฝํ•˜๊ณ  split์œผ๋กœ ๊ฐ๊ฐ์˜ ์š”์†Œ๋กœ ๋‚˜๋ˆ ์ค€ ๋’ค reverse ๋ฉ”์„œ๋“œ๋กœ ์œ„..
๋ฌธ์ œ ๋‚ด์šฉ ๐Ÿ™‍โ™‚๏ธํ’€์ด function solution(s) { const middleStrIndex = Math.floor(s.length / 2); return s.length % 2 === 0 ? s.substring(middleStrIndex - 1, middleStrIndex + 1) : s.substring(middleStrIndex, middleStrIndex + 1); } /* (ํ’€์ด) ๋ฌธ์ž์—ด s์˜ length๋ฅผ ๋ฐ˜์œผ๋กœ ๋‚˜๋ˆ„์–ด ๋ณ€์ˆ˜์— ์ €์žฅํ•˜๊ณ  index๋ฅผ ๊ธฐ์ค€์œผ๋กœ ๋ฌธ์ž์—ด์„ ์ž˜๋ผ๋‚ด๋Š” substring(start, end) ๋‚ด์žฅ๋ฉ”์„œ๋“œ๋ฅผ ์ด์šฉํ•ด s.length๊ฐ€ ์ง์ˆ˜์ผ ๊ฒฝ์šฐ ๊ฐ€์šด๋ฐ 2๊ฐœ์˜ ๋ฌธ์ž์—ด, ํ™€์ˆ˜์ผ ๊ฒฝ์šฐ ๊ฐ€์šด๋ฐ ๋ฌธ์ž์—ด 1๊ฐœ๋ฅผ ๋ฐ˜ํ™˜ํ•œ๋‹ค. **substring์€ end์˜ ์ด์ „๊นŒ์ง€ ๋ฐ˜ํ™˜ํ•˜๋ฏ€๋กœ e..
๋ฌธ์ œ ๋‚ด์šฉ ๐Ÿ™‍โ™‚๏ธํ’€์ด function solution(s) { let answer = true; const str = s.toUpperCase(); const stringArray = str.split(""); const pCount = stringArray.filter((item) => "P" === item).length; const yCount = stringArray.filter((item) => "Y" === item).length; if (pCount !== yCount) answer = false; return answer; } /* (ํ’€์ด) ์ฃผ์–ด์ง„ ๋ฌธ์ž์—ด s ๋ฅผ ๋Œ€๋ฌธ์ž๋กœ ๋ณ€๊ฒฝํ•˜๊ณ  split์„ ์ด์šฉํ•ด ๊ฐ์ž์˜ ์•ŒํŒŒ๋ฒณ์œผ๋กœ ๋‚˜๋ˆ„์–ด์ง„ ๋ฐฐ์—ด๋กœ ๋งŒ๋“ค์–ด ์ค€ ๋’ค filterํ•จ์ˆ˜๋ฅผ ์ด์šฉํ•˜์—ฌ ํ•ด๋‹นํ•˜๋Š” ์•ŒํŒŒ๋ฒณ..
YunCow
'์•Œ๊ณ ๋ฆฌ์ฆ˜ & ๋ฌธ์ œํ’€์ด/Programmers-1' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๊ธ€ ๋ชฉ๋ก (5 Page)