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

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

(230)
[์•Œ๊ณ ๋ฆฌ์ฆ˜ || ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] ๋ชจ์˜๊ณ ์‚ฌ https://school.programmers.co.kr/learn/courses/30/lessons/42840 ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”. programmers.co.kr function solution(answers) { const a = [1, 2, 3, 4, 5]; const b = [2, 1, 2, 3, 2, 4, 2, 5]; const c = [3, 3, 1, 1, 2, 2, 4, 4, 5, 5]; const checkFn = (pattern, answers) => { let test = [...answers]; const checkCount = test...
[์•Œ๊ณ ๋ฆฌ์ฆ˜ || ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] ๊ณผ์ผ ์žฅ์ˆ˜ ๋ฐฐ์—ด์€ index ๋งŒ ์ž˜ ์ด์šฉํ•ด๋„!! ์‹œ๊ฐ„ ๋ณต์žก๋„๋ฅผ ํš๊ธฐ์ ์œผ๋กœ ์ค„์ผ ์ˆ˜ ์žˆ๋‹ค!!! function solution(k, m, score) { score.sort((a, b) => b - a); let sum = 0; for (let i = 0; i index ๊ฐ€ ๊ทœ์น™์ ์ž„. ์ด๋ผ๋Š” ํžŒํŠธ๋ฅผ ์–ป์–ด ํ†ต๊ณผํ–ˆ๋‹ค. ์˜ฌ๋ฆผ ์ฐจ์ˆ˜๋กœ ์ •๋ ฌํ•ด์ค€ ๋ฐฐ์—ด์„ 4๊ฐœ์”ฉ ์ž๋ฅด๋ฉด index๊ฐ€ 4-1, 8-1... ์ด๋ ‡๊ฒŒ ๋ฐ”๋กœ ์ „ index ๋งŒ ํ•„์š”ํ•˜๊ฒŒ ๋œ๋‹ค. ํ•ด๋‹นํ•˜๋Š” index *m..
[์•Œ๊ณ ๋ฆฌ์ฆ˜ || ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] 2016๋…„ / reduce break https://school.programmers.co.kr/learn/courses/30/lessons/12901 ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”. programmers.co.kr ์˜ค๋Š˜์˜ ๋ฌธ์ œ๋Š” 2016๋…„์˜ ์›”,์ผ์ด ์ •ํ•ด์กŒ์„ ๋•Œ ์š”์ผ์„ ๊ตฌํ•˜๋Š” ๋ฌธ์ œ. ๋‚˜์˜ ๋ˆˆ๊ธธ์„ ์‚ฌ๋กœ์žก์€ '์‹ค์ œ๋กœ ์žˆ๋Š” ๋‚ ์ž…๋‹ˆ๋‹ค' ์—ฅ ๊ทธ๋Ÿผ ์ง„์งœ ๋‹ฌ๋ ฅ์ด๋ž‘ ๋˜‘๊ฐ™๋„ค? ๊ท€์ฐฎ๊ฒŒ ์œค๋…„ ๋“ฑ๋“ฑ ๊ณ„์‚ฐํ•  ํ•„์š”๊ฐ€ ์—†๊ฒ ๊ตฐ ์ด๋ผ๊ณ  ์ƒ๊ฐ์ด ๋“ค์—ˆ์Œ. https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Date/toDateString Date.prot..
[์•Œ๊ณ ๋ฆฌ์ฆ˜ || ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] ์ฝœ๋ผ๋ฌธ์ œ ๊ฐœ์ธ์ ์œผ๋กœ ์ฝœ๋ผ๋ฌธ์ œ ๊ฐ™์€ ๋ฌธ์ œ ์œ ํ˜•์ด ์‹ซ๋‹ค....... function solution(a, b, n) { let count = 0; while (n >= a) { count += Math.floor(n / a) * b; n = n % a + Math.floor(n / a) * b; } return count; } ์‚ฌ์‹ค ๊ตฌํ•˜๊ณ  ๋‚˜๋ฉด ๋ณ„๊ฑฐ ์—†์ง€๋งŒ, ๋ฌธ์ œ ๋ถ€ํ„ฐ ๋ณต์žกํ•˜๊ฒŒ ๋Š๊ปด์ง. ์•„๋ž˜๋Š” ์Šคํ„ฐ๋”” ํŒ€์›๋ถ„์˜ ํ’€์ด. ์žฌ๊ท€ํ•จ์ˆ˜๋ฅผ ์ด์šฉํ•œ ํ’€์ด๋‹ค. ์žฌ๊ท€ํ•จ์ˆ˜ ๊ฑฐ์˜ ์•ˆ์จ๋ด์„œ ๋ณผ ๋•Œ๋งˆ๋‹ค ์‹ ๊ธฐํ•˜๋‹ค.... ๊ทผ๋ฐ while ๋ฌธ์˜ ๋ฌดํ•œ๋ฃจํ”„์˜ ์œ„ํ—˜์—์„œ ๋ฒ—์–ด๋‚˜๊ธฐ์— ๊ดœ์ฐฎ์€ ๊ฒƒ ๊ฐ™๊ธฐ๋‘ ํ•˜๋‹ค! function solution(a, b, n) { function helper(b,n,a){ if((a / b) < 1) return 0; const..
[์•Œ๊ณ ๋ฆฌ์ฆ˜ || ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] ๋ฌธ์ž์—ด์ด ๋ช‡ ๋ฒˆ ๋“ฑ์žฅํ•˜๋Š”์ง€ ์„ธ๊ธฐ - reduce ํ™œ์šฉ๋ฒ• ์ด ๋ฌธ์ œ๋Š” ํ’€์—ˆ๋‹ค๊ธฐ ๋ณด๋‹จ ๋‹ค๋ฅธ ์‚ฌ๋žŒ ์ฝ”๋“œ๋ฅผ ๋ณด๊ณ  ๊ณต๋ถ€ํ–ˆ๋‹ค..! reduce ๋ฅผ ์ด์šฉํ•ด ์„ธ์•ผํ•˜๋Š” ๊ฐ’๋งŒ count ํ•ด์ค€๋‹ค. ์„ธ์•ผ ํ•˜๋Š” ๊ฐ’์€ conStr ๊ณผ pat ์„ ๋น„๊ตํ•˜๋ฉด ๋œ๋‹ค. ๋น„๊ตํ•  conStr ์€ ๊ธฐ์กด ๋ฌธ์ž๋ฅผ pat ์˜ ๊ธธ์ด๋งŒํผ์”ฉ ์ž˜๋ผ๋‚ธ ๊ฐ’์ธ๋ฐ, ์„ค๋ช…์ฒ˜๋Ÿผ ์ƒˆ๋กœ์šด ๊ฐ’์„ ๋ฐ˜ํ™˜ํ•˜๊ธฐ ๋•Œ๋ฌธ์— ๊ธฐ์กด์— ์ฃผ์–ด์ง„ myString ์—๋Š” ์˜ํ–ฅ์„ ๋ฏธ์น˜์ง€ ์•Š๋Š”๋‹ค. function solution(myString, pat) { const result = [...myString].reduce((acc, cur, ind) => { const conStr = myString.slice(ind, pat.length + ind) console.log(acc, cur, ind) return conStr === pat ? acc + 1..
[์•Œ๊ณ ๋ฆฌ์ฆ˜ || ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] ๋ฐฐ์—ด์˜ ๊ธธ์ด๋ฅผ 2์˜ ๊ฑฐ๋“ญ์ œ๊ณฑ์œผ๋กœ ๋งŒ๋“ค๊ธฐ ๋ฒ”์œ„๊ฐ€ ์–ด์ฐจํ”ผ 1000๊นŒ์ง€ ๋ฐ–์— ์—†๊ธธ๋ž˜, function solution(arr) { const p2 = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024]; const pow = p2.findIndex(v => arr.length arr[i] ? v = arr[i] : v); return zero; } ํ•ด๋ดค์ž 2์˜ 10 ์ œ๊ณฑ์ธ 1024๊นŒ์ง€ ๋ฐ–์— ์•ˆ๊ฐˆ๊ฑฐ ๊ฐ™์•„์„œ ์ด๋ ‡๊ฒŒ ํ’€์—ˆ๋Š”๋”ฉ.. ๋ชฌ๊ฐ€.. ํ‡ดํ™”ํ•œ ๋Š๋‚Œ... function solution(arr) { const length = arr.length; const totalLength = 2 ** Math.ceil(Math.log2(length)); return [...arr, ...new Array(totalLength - le..
[์•Œ๊ณ ๋ฆฌ์ฆ˜ || ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] ๋‘ ๊ฐœ ๋ฝ‘์•„์„œ ๋”ํ•˜๊ธฐ ์ฒ˜์Œ์—” ๋ชจ๋“  ์ˆ˜๋ฅผ ๋”ํ•œ๊ฑธ Set ์œผ๋กœ ๋งŒ๋“ค์–ด์„œ ์ค‘๋ณต๋˜๋Š” ์ˆ˜๋ฅผ ์—†์•จ๊นŒ ํ•˜๋‹ค๊ฐ€, ๊ทธ๋Ÿผ ๊ฐ™์€ ๊ฐ™์€ 1, 3 ์„ ๋”ํ•œ ๊ฒƒ๊ณผ 3, 1 ์„ ๋”ํ•˜๋ฉด ๊ฐ™์€๋ฐ ๊ตณ์ด ํ•ด์•ผํ•˜๋‚˜ ์ƒ๊ฐ์ด ๋“ค์—ˆ๋‹ค. function solution(numbers) { let sums = []; numbers.map((v, i) => numbers.map((v1, i1) => i !== i1 && !sums.includes(v + v1) && sums.push(v + v1))) return sums.sort((a, b)=> a - b); } ์–ด์จŒ๋“  ๋ฐ˜๋ณต๋ฌธ์„ ๋‘๋ฒˆ ๋Œ์•„์•ผํ•˜๋Š”๋ฐ, ๊ทธ๋Ÿผ ์˜ˆ์™ธ๋ฅผ ๋‘ฌ์„œ ์ตœ๋Œ€ํ•œ ๋œ ์—ฐ์‚ฐํ•˜๋„๋ก ํ•ด๋ณด์ž..! ๋ผ๋Š” ์ƒ๊ฐ์œผ๋กœ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ–ˆ๋‹ค. ๊ทผ๋ฐ ์ง€๊ธˆ ์ž‘์„ฑํ•˜๋ฉด์„œ ๋‹ค์‹œ ๋ณด๋‹ˆ, ์–ด์ฐจํ”ผ includes ํ•  ๋•Œ ์ „๋ถ€ ๊ณ„์‚ฐํ•˜๊ธด ํ•˜๋„ค......
[์•Œ๊ณ ๋ฆฌ์ฆ˜ || ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] ํ‘ธ๋“œ ํŒŒ์ดํŠธ ๋Œ€ํšŒ function solution(food) { let oneCount = []; food.map((v, i) => i > 0 && oneCount.push(Math.floor(v / 2))) const arr = oneCount.map((v, i) => new Array(v).fill(i + 1)).flat(); const rev = [...arr].reverse().join(""); console.log(arr.join("") + "0" + rev) } ์ฒ˜์Œ์— ํ‘ผ ๋ฐฉ๋ฒ•. ๊ทผ๋ฐ ์—ฌ๊ธฐ์„œ ๋ญ”๊ฐ€ ๋” ์ค„์ผ ์ˆ˜ ์žˆ์„ ๊ฒƒ ๊ฐ™์•˜๋‹ค. function solution(food) { const arr = food.map((v, i) => { return new Array(Math.floor(v / 2)).fill(i); ..

728x90
๋ฐ˜์‘ํ˜•