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

ํ”„์—” ๊ณต๋ถ€

(151)
[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค/Javascript] [level.0] ๋ฐฐ์—ด ํšŒ์ „์‹œํ‚ค || ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์ž…๋ฌธ function solution(numbers, direction) { var answer = []; if ("right" == direction) { numbers.unshift(numbers.pop()); } else { numbers.push(numbers.shift()); } answer = numbers; return answer; } ์ œ์ผ ๋ฒ ์ŠคํŠธ๋ผ๊ณ  ์ƒ๊ฐํ•˜๋Š” ์ฝ”๋“œ. Array.prototype.pop() https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Array/pop Array.prototype.pop() - JavaScript | MDN pop() ๋ฉ”์„œ๋“œ๋Š” ๋ฐฐ์—ด์—์„œ ๋งˆ์ง€๋ง‰ ์š”์†Œ๋ฅผ ์ œ๊ฑฐํ•˜๊ณ  ๊ทธ ์š”์†Œ๋ฅผ ..
[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค/Javascript] [level.0] ์ธ๋ฑ์Šค ๋ฐ”๊พธ๊ธฐ || ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์ž…๋ฌธ function solution(my_string, num1, num2) { const num11 = [...my_string][num1]; const num22 = [...my_string][num2]; let resultAyy = [...my_string]; resultAyy[num1] = num22; resultAyy[num2] = num11; return resultAyy.join(""); } ๋‚˜์˜ ํ’€์ด. ํŠน๋ณ„ํ•œ ๋ฌ˜์ˆ˜๊ฐ€ ๋– ์˜ค๋ฅด์ง€ ์•Š์•„ ์ฐจ๊ทผ์ฐจ๊ทผ ๊ฐ’์„ ๋ณ€๊ฒฝํ–ˆ๋‹ค. ๋งจ๋‚  ํ’€ ๋•Œ๋งˆ๋‹ค ์•„ ๋ถ„๋ช… ์—„์ฒญ ์‹ฌํ”Œํ•˜๊ฒŒ ํ‘œํ˜„ํ•˜๋Š” ๋ฐฉ๋ฒ•์ด ์žˆ์„ํ…๋ฐ,, ๋ผ๋Š” ์ƒ๊ฐ์ด ๋“ ๋‹ค. ํ•˜์ง€๋งŒ ๊ณ„์† ๋‹ค๋ฅธ์‚ฌ๋žŒ์˜ ํ’€์ด๋ฅผ ๋ณด๋ฉฐ ์ฐธ๊ณ ํ•˜๋‹ค๋ณด๋ฉด ์š”๋ น์ด ์ƒ๊ธฐ๋Š” ๋Š๋‚Œ! (๋‹จ๋ฒˆ์— ์ดํ•ด๊ฐ€๊ฑฐ๋‚˜ ๋ฐ”๋กœ ์ ์šฉํ•œ ๊ฒƒ๋“ค์€ ๋ธ”๋กœ๊ทธ์— ์“ฐ์ง€ ์•Š์•˜๋‹ค. ๋‹ด์—” ๊ทธ๋Ÿฐ๊ฒƒ๋“ค ์ข€ ๊ธฐ๋ก..
[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค/Javascript] [level.0] ํŠน์ • ๋ฌธ์ž ์ œ๊ฑฐํ•˜๊ธฐ || ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์ž…๋ฌธ ๐Ÿšฅ replace() ์™€ for๋ฌธ ์ด์šฉ function solution(my_string, letter) { var answer = ""; for (let i = 0; i < my_string.length; i++) { my_string = my_string.replace(letter, ""); } answer = my_string; return answer; } replace ๋งŒ ์•Œ์•„์„œ ์ด๋ ‡๊ฒŒ ๊ตฌํ˜„ํ–ˆ๋‹ค. ๐Ÿšฅ replaceAll() ํ•˜์ง€๋งŒ for ๋ฌธ์„ ์‚ฌ์šฉํ•˜์ง€ ์•Š์•„๋„ ๋˜์—ˆ๋‹ค replaceAll ์ด๋ž€๊ฒŒ ์žˆ์—ˆ์Œ! function solution(my_string, letter) { return my_string.replaceAll(letter, ""); } ์–˜๊ฐ€ ํ™œ์šฉ๋„๊ฐ€ ํ›จ์”ฌ ๋†’์„ ๊ฒƒ ๊ฐ™๋‹ค. https://..
[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค/Javascript] [level.0] ์ค‘์•™๊ฐ’ ๊ตฌํ•˜๊ธฐ || ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์ž…๋ฌธ function solution(array) { array.sort((a, b) => a - b); const middleIndex = Math.floor(array.length / 2); var answer = array[middleIndex]; return answer; } ๋ฌธ์ œ์—์„œ์˜ ์ค‘์•™๊ฐ’์€ ์œ„์น˜๊ฐ€ ์•„๋‹ˆ๋ผ ํฐ ์ˆ˜๋ถ€ํ„ฐ ์„ธ์› ์„ ๋•Œ์˜ ์ค‘์•™๊ฐ’์„ ์–˜๊ธฐํ•˜๋Š” ๊ฒƒ. (์ฒจ์— ์œ„์น˜๋งŒ ์ค‘์•™๊ฐ’์œผ๊ณ  ๊ตฌํ•จ ๐Ÿ˜–) 1. ๋ฐฐ์—ด์˜ ์ˆœ์„œ๋ฅผ sort ๋ฅผ ์ด์šฉํ•ด ์ž‘์€ ์ˆ˜ ๋ถ€ํ„ฐ ์ •๋ ฌํ•œ๋‹ค. ์ˆซ์ž์˜ ๊ฒฝ์šฐ ๋‘ ์ˆ˜๋ฅผ ๋นผ์„œ ์Œ์ˆ˜/์–‘์ˆ˜๊ฐ€ ๋‚˜์˜ค๋Š” ๊ฒฐ๊ณผ์— ๋”ฐ๋ผ index ๊ฐ€ ๊ฒฐ์ •๋œ๋‹ค. https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Array/sort Array..
[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค/Javascript] [level.0] ์ ์˜ ์œ„์น˜ ๊ตฌํ•˜๊ธฐ|| ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์ž…๋ฌธ function solution(dot) { var answer = 0; if (dot[0] > 0) { answer = dot[1] > 0 ? 1 : 4; } else { answer = dot[1] > 0 ? 2 : 3; } return answer; } ์š”๊ฑด if ๋ฌธ์œผ๋กœ ํ’€์–ด์ผ์„ ๋•Œ dot[0] ์ด ์–‘์ˆ˜์ธ์ง€ ์Œ์ˆ˜์ธ์ง€์— ๋”ฐ๋ผ ๋‚˜๋ˆ„๊ณ , ๊ทธ ํ›„์— dot[1] ๊ฐ’์ด ์–‘์ˆ˜๋ƒ ์Œ์ˆ˜๋ƒ์— ๋”ฐ๋ผ answer์— ๊ฐ’์„ ๋„ฃ์–ด์ฃผ๋Š” ํ˜•์‹์œผ๋กœ ๊ตฌ์„ฑํ–ˆ๋‹ค. ๊ทผ๋ฐ ๊ถ๊ธˆํ–ˆ๋˜๊ฒŒ ์ด์ค‘์œผ๋กœ ์‚ผํ•ญ์—ฐ์‚ฐ์ž๋ฅผ ์“ธ ์ˆ˜ ์žˆ์„๊นŒ ์˜€๋‹ค. function solution(dot) { var answer = 0; dot[0] > 0 ? (answer = dot[1] > 0 ? 1 : 4) : (answer = dot[1] > 0 ? 2 : 3); retu..
[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค/Javascript] [level.0] ์–‘๊ผฌ์น˜ || ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์ž…๋ฌธ function solution(n, k) { var answer = 12000 * n + 2000 * (k - parseInt(n / 10)); return answer; } ์Œ๋ฃŒ์ˆ˜์˜ ๊ฐœ์ˆ˜ k์—์„œ ์–‘๊ผฌ์น˜์˜ n ์ธ๋ถ„์„ 10์œผ๋กœ ๋‚˜๋ˆˆ ๋งŒํผ ๋นผ์ฃผ๋ฉด, ์„œ๋น„์Šค ์™ธ์˜ ๋งˆ์‹  ์Œ๋ฃŒ์ˆ˜์˜ ๊ฐœ์ˆ˜๊ฐ€ ๋‚˜์˜จ๋‹ค~
[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค/Javascript] [level.0] ์ง์ˆ˜์˜ ํ•ฉ|| ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์ž…๋ฌธ ์•„.. ์š”์ฆ˜ ๋จ๋จ์ด ๊ฐ™๋‹ค๋Š” ์ƒ๊ฐ์ด ๋งŽ์ด ๋“œ๋Š”๋ฐ,, function solution(n) { var answer = 0; for (let i = 2; i
[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค/Javascript] [level.0] ๊ฐ๋„๊ธฐ || ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์ž…๋ฌธ ์š” ๋ฉฐ์น  ๋ฐฑ์ค€ ํ—ˆ๋ธŒ๊ฐ€ ์•ˆ๋˜๊ธธ๋ž˜ ํ˜ผ์ž ๋งž์ถฐ๋ณด๋‹ค๊ฐ€, ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค๋Š” ๋œ๋‹ค๋Š” ์–˜๊ธฐ๊ฐ€ ์žˆ์–ด ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค๋กœ ์˜ฎ๊ฒจ๋ดค๋‹ค. UI๋„ ๊น”๋”ํ•˜๊ณ  ๋ญ”๊ฐ€ ํ›จ์”ฌ ๊ธฐ์—…์ฒด์˜ ์‚๊นŒํ•œ ๋Š๋‚Œ์ด ์žˆ๋‹คใ…‹ใ…‹ใ…‹ ๋ฌด์—‡๋ณด๋‹ค readFileSync๋กœ input์„ ๋ฐ›์•„์˜ค์ง€ ์•Š์•„๋„ ๋˜๋Š”๊ฒŒ ์ •๋ง ํŽธ๋ฆฌํ•˜๋‹ค!! ์—ฌ๊ธฐ๋Š” ๋ฌธ์ œ๊ฐ€ ๋ฒˆํ˜ธ๋กœ ๋˜์–ด์žˆ๋Š”๊ฒŒ ์•„๋‹ˆ๋ผ ์ œ๋ชฉ๊ณผ ๋‹จ๊ณ„๋กœ ๊ตฌ๋ถ„๋˜์–ด์žˆ๋‹ค. ์—ฐ์‚ฐ์—์„œ๋Š” ๋„ˆ๋ฌด ๊ธฐ์ดˆ์ ์ธ๊ฑด ์•ˆ์˜ฌ๋ฆฌ๊ณ , ์ž‘์„ฑํ•ด์•ผํ•  ์˜๋ฏธ๊ฐ€ ์žˆ๋Š” ๊ฒƒ๋“ค๋งŒ ์˜ฌ๋ฆฌ๊ธฐ๋กœ. function solution(angle) { var answer = 0; if (angle === 90) { answer = 2; } else if (0 < angle && angle < 90) { answer = 1; } else if (angle === 180) { answer = 4; } else i..

728x90
๋ฐ˜์‘ํ˜•