๐ŸŒ Jero's Wiki/Algorithms

๐Ÿง Problems์™ธ๊ณผ์˜์‚ฌ ๋จธ์“ฑ์ด๋Š” ์‘๊ธ‰์‹ค์— ์˜จ ํ™˜์ž์˜ ์‘๊ธ‰๋„๋ฅผ ๊ธฐ์ค€์œผ๋กœ ์ง„๋ฃŒ ์ˆœ์„œ๋ฅผ ์ •ํ•˜๋ ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค. ์ •์ˆ˜ ๋ฐฐ์—ด emergency๊ฐ€ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์งˆ ๋•Œ ์‘๊ธ‰๋„๊ฐ€ ๋†’์€ ์ˆœ์„œ๋Œ€๋กœ ์ง„๋ฃŒ ์ˆœ์„œ๋ฅผ ์ •ํ•œ ๋ฐฐ์—ด์„ return ํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด์ฃผ์„ธ์š”. ๐Ÿ’ก Solutionsfunction solution(emergency) { const descending = [...emergency].sort((a, b) => b - a); return emergency.map(value => descending.indexOf(value) + 1);}์ฝ”๋“œ ์„ค๋ช…sort( ) ๋ฉ”์„œ๋“œ๋ฅผ ํ™œ์šฉํ•ด ๋ฐฐ์—ด ์š”์†Œ๋ฅผ ๋‚ด๋ฆผ์ฐจ์ˆœ์œผ๋กœ ์ •๋ ฌํ•ด์ค๋‹ˆ๋‹ค. ์ด๋•Œ, ๋ฐฐ์—ด์— ๋ฐ”๋กœ sort( )๋ฅผ ์ ์šฉํ•˜๋ฉด ์›..
๐Ÿง Problems์ตœ๋นˆ๊ฐ’์€ ์ฃผ์–ด์ง„ ๊ฐ’ ์ค‘์—์„œ ๊ฐ€์žฅ ์ž์ฃผ ๋‚˜์˜ค๋Š” ๊ฐ’์„ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค. ์ •์ˆ˜ ๋ฐฐ์—ด array๊ฐ€ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์งˆ ๋•Œ, ์ตœ๋นˆ๊ฐ’์„ return ํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด๋ณด์„ธ์š”. ์ตœ๋นˆ๊ฐ’์ด ์—ฌ๋Ÿฌ ๊ฐœ๋ฉด -1์„ return ํ•ฉ๋‹ˆ๋‹ค. ๐Ÿ’ก Solutionsconst solution = (array) => { const frequency = {}; array.forEach(num => { frequency[num] = (frequency[num] || 0) + 1; }); const maxFreq = Math.max(...Object.values(frequency)); const modes = Object.keys(frequency).f..
๐Ÿง Problems์ฒซ ๋ฒˆ์งธ ๋ถ„์ˆ˜์˜ ๋ถ„์ž์™€ ๋ถ„๋ชจ๋ฅผ ๋œปํ•˜๋Š” numer1, denom1, ๋‘ ๋ฒˆ์งธ ๋ถ„์ˆ˜์˜ ๋ถ„์ž์™€ ๋ถ„๋ชจ๋ฅผ ๋œปํ•˜๋Š” numer2, denom2๊ฐ€ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์ง‘๋‹ˆ๋‹ค. ๋‘ ๋ถ„์ˆ˜๋ฅผ ๋”ํ•œ ๊ฐ’์„ ๊ธฐ์•ฝ ๋ถ„์ˆ˜๋กœ ๋‚˜ํƒ€๋ƒˆ์„ ๋•Œ ๋ถ„์ž์™€ ๋ถ„๋ชจ๋ฅผ ์ˆœ์„œ๋Œ€๋กœ ๋‹ด์€ ๋ฐฐ์—ด์„ return ํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด๋ณด์„ธ์š”. ๐Ÿ’ก Solutionsconst gcd = (num1, num2) => num2 === 0 ? num1 : gcd(num2, num1 % num2);const solution = (numer1, denom1, numer2, denom2) => { const numer = numer1 * denom2 + numer2 * denom1; const denom =..