[JavaScript] for ๋ฐ˜๋ณต๋ฌธ

๋””๋”ฉยท2022๋…„ 11์›” 1์ผ
0

Today I Learned

๋ชฉ๋ก ๋ณด๊ธฐ
3/12
post-thumbnail

๐Ÿ“ 2022. 11. 01

JavaScript / ์ฝ”ํ”Œ๋ฆฟ ๋ณต์Šต



๐Ÿ“Œ Today I Learned

  • ๋ฐ˜๋ณต๋ฌธ 8๋ฒˆ makeOddDigits
  • ๋ฐ˜๋ณต๋ฌธ 10๋ฒˆ makeMultiplesOfDigit2
  • ๋ฐ˜๋ณต๋ฌธ 11๋ฒˆ countCharacter
  • ๋ฐ˜๋ณต๋ฌธ 12๋ฒˆ getMaxNumberFromString

๐Ÿ’ฌ makeMultiplesOfDigit2

๐Ÿงท ๋ž˜ํผ๋Ÿฐ์Šค ์ฝ”๋“œ

function makeOddDigits(num) {
  let result = '';

  let count = 0;
  let i = 1;
  while (count < num) {
    result = result + String(i);
    i = i + 2;
    count++;
  }

  return result;
}

๐Ÿงป ๋‚ด๊ฐ€ ์ƒ๊ฐํ•œ ํ’€์ด

์กฐ๊ฑด count๊ฐ€ num๋ณด๋‹ค ์ž‘์„ ๋•Œ {} ๋ฐ”๋”” ์ฝ”๋“œ๊ฐ€ ์‹คํ–‰๋œ๋‹ค

{ result = result + String(i) // ๋ฆฌ์ ˆํŠธ๋Š” ๋ฆฌ์ ˆํŠธ ํ”Œ๋Ÿฌ์Šค ๋ฌธ์ž์—ด I๋‹ค // โ€˜โ€™์€ โ€˜โ€™+ i = 1
// ๋นˆ ์ŠคํŠธ๋ง ๊ฐ’ + ๋ฌธ์ž์—ด ๋ฐฐ์—ด

์ˆซ์ž 1๋กœ ํ•œ ๋ฒˆ ๋Œ์•˜๊ธฐ ๋•Œ๋ฌธ์— ํ™€์ˆ˜๊ฐ’์œผ๋กœ ๋งŒ๋“ค์–ด ์ค˜์•ผ ํ•จ

i = i +2 (i๋Š” ํ˜„์žฌ 1์ด๊ธฐ ๋•Œ๋ฌธ์— 1๋ฒˆ ๋Œ ๋•Œ์ด๋‹ˆ 1+2=3 ํ™€์ˆ˜๊ฐ€ ๋˜์–ด์•ผ ํ•จ
count++ // ์นด์šดํŠธ๊ฐ’ ๋ฐ˜๋ณต
๋ช‡ ๋ฒˆ ๋ฐ˜๋ณตํ•  ๊ฑด์ง€
}

i๋Š” ๊ฐ’์ด +2๊ฐ€ ๋˜๊ธฐ ๋•Œ๋ฌธ์— count๋กœ ๊ฐ’์„ ํ• ๋‹นํ•ด์„œ ๋ฐ˜๋ณต๋  ์กฐ๊ฑด์„ while์— ๊ฑธ์–ด ์ค€ ๋“ฏ

profile
๋ฌด์‚ฌ์™€์š”... ์—ด๊ณตํ–์š”...

0๊ฐœ์˜ ๋Œ“๊ธ€