<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
    <channel>
        <title>woo7i.log</title>
        <link>https://velog.io/</link>
        <description>방법을 연구할 줄 아는 개발자!</description>
        <lastBuildDate>Wed, 30 Aug 2023 03:05:00 GMT</lastBuildDate>
        <docs>https://validator.w3.org/feed/docs/rss2.html</docs>
        <generator>https://github.com/jpmonette/feed</generator>
        <image>
            <title>woo7i.log</title>
            <url>https://velog.velcdn.com/images/woo_7i/profile/471bd1d3-d7f2-4a3d-ab77-8c33086a12f0/social_profile.jpeg</url>
            <link>https://velog.io/</link>
        </image>
        <copyright>Copyright (C) 2019. woo7i.log. All rights reserved.</copyright>
        <atom:link href="https://v2.velog.io/rss/woo_7i" rel="self" type="application/rss+xml"/>
        <item>
            <title><![CDATA[🟣 오늘의 문제 정리]]></title>
            <link>https://velog.io/@woo_7i/%EC%98%A4%EB%8A%98%EC%9D%98-%EB%AC%B8%EC%A0%9C-%EC%A0%95%EB%A6%AC-y8woh6kz</link>
            <guid>https://velog.io/@woo_7i/%EC%98%A4%EB%8A%98%EC%9D%98-%EB%AC%B8%EC%A0%9C-%EC%A0%95%EB%A6%AC-y8woh6kz</guid>
            <pubDate>Wed, 30 Aug 2023 03:05:00 GMT</pubDate>
            <description><![CDATA[<h3 id="😭-문제-핥짝-1">😭 문제 핥짝 #1</h3>
<blockquote>
<p><strong>[엘리스 SW 엔지니어 트랙]</strong> 빼곡히 채운 삼각형</p>
</blockquote>
<p><strong>문제 설명</strong> 
빨간색, 녹색 또는 검정색의 색상으로 이루어진 행이 있습니다. 이 행을 일정한 규칙을 통해 행이 생성되어 삼각형이 완성됩니다.</p>
<p>이전 행에서 두 쌍의 색상을 고려하여 각각 마지막 행보다 하나 적은 색상을 포함하는 연속 행이 생성됩니다.</p>
<p>두 쌍의 색상이 동일하면 새 행에 동일한 색상이 사용되고 서로 다른 경우 누락된 색상이 새 행에 사용됩니다. 이런식으로 단 하나의 색상만 있는 마지막 행이 남을 때까지 생성됩니다.</p>
<p>예를들어 R R G B R G B B행을 입력 받으면 아래와 같은 삼각형이 만들어집니다. 맨 아래 행에 나타날 색상을 반환하는 함수를 작성하세요.</p>
<pre><code>R R G B R G B B
 R B R G B R B
  G G B R G G
   G R G B G
    B B R R
     B G R
      R B
       G</code></pre><p><strong>제한사항</strong></p>
<ul>
<li>입력 문자열에는 대문자 ‘B’, ‘G’ 또는 ‘R’만 포함되어야 한다.</li>
<li>입력 문자열의 길이는 최소 2글자 이상이다.</li>
</ul>
<p><strong>입출력 예</strong></p>
<table>
<thead>
<tr>
<th align="center">dots</th>
<th align="center">result</th>
</tr>
</thead>
<tbody><tr>
<td align="center">&#39;RRGBRGBB&#39;</td>
<td align="center">&#39;G&#39;</td>
</tr>
<tr>
<td align="center">&#39;RBRGB&#39;</td>
<td align="center">&#39;B&#39;</td>
</tr>
</tbody></table>
<p><strong>지시사항</strong> </p>
<ul>
<li>삼각형의 첫 번째 행이 문자열로 주어지고 맨 아래 행에 문자열로 나타날 최종 색상을 반환하는 함수를 작성하세요.</li>
</ul>
<hr>
<h3 id="나의-풀이">나의 풀이</h3>
<pre><code class="language-js">function triangle(row) {
  // row == &#39;RBRGB&#39;
  while (row.length &gt; 1) {
    let tempStr = &#39;&#39;;
    for (let i = 0; i &lt; row.length - 1; i++) {
      tempStr += color(row[i], row[i + 1]);
    }                  // R        B
    row = tempStr;
  }         // GGBR
            // GRG
            // BB
            // B
  return row;
}

function color(c1, c2) {
  const colors = [&#39;B&#39;, &#39;G&#39;, &#39;R&#39;];
  if (c1 === c2) {
    return c1;
  } else {
    return colors.filter(c =&gt; c !== c1 &amp;&amp; c !== c2)[0];
  }
}

console.log(triangle(&#39;RBRGB&#39;));

module.exports = { triangle };
</code></pre>
<p>💡 <strong>입/출력 접근</strong></p>
<ol>
<li>input String(row)의 조건을 충족하는지 확인하세요.
조건: 입력 문자열에는 대문자 ‘B’, ‘G’ 또는 ‘R’만 포함되어야 한다.</li>
<li>지시사항의 규칙데로 두 쌍의 색을 비교해서 새로운 색상을 반환하는 코드를 작성합니다.<ol start="3">
<li>기존의 행보다 1만큼 짧아진 행을 생성하고 color()함수로 대체된 문자열을 반환하세요.</li>
</ol>
</li>
</ol>
<p>=&gt; 두 함수를 키워드로 사용해서 답을 반환 해야하는 함수에 해당 함수를 적용하는 식으로 접근해야 했었다.. 
알고리즘 문제 해결에 있어서는 처음 접하는 접근식이었어서 결국 해답을 봐야했던,,</p>
<p>일급객체로서 함수들를 사용하는 방법을 익숙해져야겠다는 생각이 가득..ㅠㅠ</p>
]]></description>
        </item>
        <item>
            <title><![CDATA[🟣 오늘의 문제 정리]]></title>
            <link>https://velog.io/@woo_7i/%EC%98%A4%EB%8A%98%EC%9D%98-%EB%AC%B8%EC%A0%9C-%EC%A0%95%EB%A6%AC</link>
            <guid>https://velog.io/@woo_7i/%EC%98%A4%EB%8A%98%EC%9D%98-%EB%AC%B8%EC%A0%9C-%EC%A0%95%EB%A6%AC</guid>
            <pubDate>Mon, 14 Aug 2023 13:55:53 GMT</pubDate>
            <description><![CDATA[<h3 id="😭-문제-핥짝-1">😭 문제 핥짝 #1</h3>
<blockquote>
<p><strong>[프로그래머스]</strong> Lv0 : 직사각형 넓이 구하기</p>
</blockquote>
<p><strong>문제 설명</strong> 
2차원 좌표 평면에 변이 축과 평행한 직사각형이 있습니다. 직사각형 네 꼭짓점의 좌표 [[x1, y1], [x2, y2], [x3, y3], [x4, y4]]가 담겨있는 배열 dots가 매개변수로 주어질 때, 직사각형의 넓이를 return 하도록 solution 함수를 완성해보세요.</p>
<p><strong>제한사항</strong></p>
<ul>
<li>dots의 길이 = 4</li>
<li>dots의 원소의 길이 = 2</li>
<li>-256 &lt; dots[i]의 원소 &lt; 256</li>
<li>잘못된 입력은 주어지지 않습니다.</li>
</ul>
<p><strong>입출력 예</strong></p>
<table>
<thead>
<tr>
<th align="center">dots</th>
<th align="center">result</th>
</tr>
</thead>
<tbody><tr>
<td align="center">[[1, 1], [2, 1], [2, 2], [1, 2]]</td>
<td align="center">1</td>
</tr>
<tr>
<td align="center">[[-1, -1], [1, 1], [1, -1], [-1, 1]]</td>
<td align="center">4</td>
</tr>
</tbody></table>
<ul>
<li><p>좌표 [[1, 1], [2, 1], [2, 2], [1, 2]] 를 꼭짓점으로 갖는 직사각형의 가로, 세로 길이는 각각 1, 1이므로 직사각형의 넓이는 1 x 1 = 1입니다.</p>
</li>
<li><p>좌표 [[-1, -1], [1, 1], [1, -1], [-1, 1]]를 꼭짓점으로 갖는 직사각형의 가로, 세로 길이는 각각 2, 2이므로 직사각형의 넓이는 2 x 2 = 4입니다.</p>
</li>
</ul>
<hr>
<h3 id="나의-풀이">나의 풀이</h3>
<pre><code class="language-js">function solution(dots) {
    let garo= 0;
    let sero= 0;

    for(let i=0; i &lt; dots.length-1; i++){
        const [x,y] = dots[i]
        const [nx,ny] = dots[i+1]

        garo = Math.max(Math.abs(nx-x), garo)
        sero = Math.max(Math.abs(ny-y), sero)
    }


    return garo * sero
}</code></pre>
<p>💡 <strong>입/출력 접근</strong></p>
<ol>
<li>직사각형의 넓이를 구하는 공식은 가로 x 세로</li>
<li>각 변의 길이를 알아내야 함.</li>
<li>랜덤으로 입력되는 각 꼭지점의 포인트들
3-1. 입력 값의 dots의 배열을 순회하여 각 값의 포인트를 구조분해 할당으로 정의.
3-2. 다음 포인트까지 한번에 구해서 모두를 합산한 경우의 수 중</li>
<li>변의 길이를 가질 가장 큰 값을 추출.
4-1. for문 안에 식을 작섬함으로써 계속해서 max가 되는 값을 <strong>초기화</strong>하여 가장 큰 값을 찾아냄.</li>
<li>return 가로 x 세로</li>
</ol>
<hr>
<h3 id="😭-문제-핥짝-2">😭 문제 핥짝 #2</h3>
<blockquote>
<p><strong>[프로그래머스]</strong> Lv0 : 캐릭터의 좌표</p>
</blockquote>
<p><strong>문제 설명</strong> 
머쓱이는 RPG게임을 하고 있습니다. 게임에는 up, down, left, right 방향키가 있으며 각 키를 누르면 위, 아래, 왼쪽, 오른쪽으로 한 칸씩 이동합니다. 예를 들어 [0,0]에서 up을 누른다면 캐릭터의 좌표는 [0, 1], down을 누른다면 [0, -1], left를 누른다면 [-1, 0], right를 누른다면 [1, 0]입니다. 머쓱이가 입력한 방향키의 배열 keyinput와 맵의 크기 board이 매개변수로 주어집니다. 캐릭터는 항상 [0,0]에서 시작할 때 키 입력이 모두 끝난 뒤에 캐릭터의 좌표 [x, y]를 return하도록 solution 함수를 완성해주세요.</p>
<ul>
<li>[0, 0]은 board의 정 중앙에 위치합니다. 예를 들어 board의 가로 크기가 9라면 캐릭터는 왼쪽으로 최대 [-4, 0]까지 오른쪽으로 최대 [4, 0]까지 이동할 수 있습니다.</li>
</ul>
<br>

<p><strong>제한사항</strong></p>
<ul>
<li>board은 [가로 크기, 세로 크기] 형태로 주어집니다.</li>
<li>board의 가로 크기와 세로 크기는 홀수입니다.</li>
<li>board의 크기를 벗어난 방향키 입력은 무시합니다.</li>
<li>0 ≤ keyinput의 길이 ≤ 50</li>
<li>1 ≤ board[0] ≤ 99</li>
<li>1 ≤ board[1] ≤ 99</li>
<li>keyinput은 항상 up, down, left, right만 주어집니다.</li>
</ul>
<p><strong>입출력 예</strong></p>
<table>
<thead>
<tr>
<th align="center">keyinput</th>
<th align="center">board</th>
<th align="center">result</th>
</tr>
</thead>
<tbody><tr>
<td align="center">[&quot;left&quot;, &quot;right&quot;, &quot;up&quot;, &quot;right&quot;, &quot;right&quot;]</td>
<td align="center">[11, 11]</td>
<td align="center">[2,1]</td>
</tr>
<tr>
<td align="center">[&quot;down&quot;, &quot;down&quot;, &quot;down&quot;, &quot;down&quot;, &quot;down&quot;]</td>
<td align="center">[7, 9]</td>
<td align="center">[0, -4]</td>
</tr>
</tbody></table>
<ul>
<li><p>[0, 0]에서 왼쪽으로 한 칸 오른쪽으로 한 칸 위로 한 칸 오른쪽으로 두 칸 이동한 좌표는 [2, 1]입니다.</p>
</li>
<li><p>[0, 0]에서 아래로 다섯 칸 이동한 좌표는 [0, -5]이지만 맵의 세로 크기가 9이므로 아래로는 네 칸을 넘어서 이동할 수 없습니다. 따라서 [0, -4]를 return합니다.</p>
</li>
</ul>
<hr>
<h3 id="나의-풀이-1">나의 풀이</h3>
<pre><code class="language-js">function solution(keyinput, board) {
    let x = 0;
    let y = 0;
    const maxXsize = Math.floor(board[0]/2)
    const maxYsize = Math.floor(board[1]/2)

    for(let i =0; i &lt; keyinput.length; i++){
        let item = keyinput[i]
        if(item === &#39;left&#39; &amp;&amp; x &gt; -maxXsize ) {
            x--
        }
        if(item === &#39;right&#39; &amp;&amp; x &lt; maxXsize){
            x++
        }
        if(item === &#39;up&#39;&amp;&amp; y &lt; maxYsize){
            y++
        }
        if(item === &#39;down&#39;&amp;&amp; y &gt; -maxYsize){
            y--
        }
    }
    return [x, y]
}</code></pre>
<p>💡 <strong>입/출력 접근</strong></p>
<ol>
<li>조건보다는 keyinput의 입력 배열을 순회하여 각각의 키워드를 얻음</li>
<li>if 조건을 통해 해당 키워드에 맞게 x, y 값을 더하거나 뺌</li>
<li>하지만 board의 최대, 최소 값 때문에 board 값의 경계 안에서 움직여야 하는 캐릭터.</li>
<li>절반을 나눈 값을 최대 값으로 정한 후 &amp;&amp; 연산자를 통해 조건을 추가해준다.</li>
<li>return [x, y]</li>
</ol>
<hr>
<h3 id="😭-문제-핥짝-3">😭 문제 핥짝 #3</h3>
<blockquote>
<p><strong>[프로그래머스]</strong> Lv0 : 다항식 더하기</p>
</blockquote>
<p><strong>문제 설명</strong> 
한 개 이상의 항의 합으로 이루어진 식을 다항식이라고 합니다. 다항식을 계산할 때는 동류항끼리 계산해 정리합니다. 덧셈으로 이루어진 다항식 polynomial이 매개변수로 주어질 때, 동류항끼리 더한 결괏값을 문자열로 return 하도록 solution 함수를 완성해보세요. 같은 식이라면 가장 짧은 수식을 return 합니다.</p>
<br>

<p><strong>제한사항</strong></p>
<ul>
<li><p>0 &lt; polynomial에 있는 수 &lt; 100</p>
</li>
<li><p>polynomial에 변수는 &#39;x&#39;만 존재합니다.</p>
</li>
<li><p>polynomial은 양의 정수, 공백, ‘x’, ‘+&#39;로 이루어져 있습니다.</p>
</li>
<li><p>항과 연산기호 사이에는 항상 공백이 존재합니다.</p>
</li>
<li><p>공백은 연속되지 않으며 시작이나 끝에는 공백이 없습니다.</p>
</li>
<li><p>하나의 항에서 변수가 숫자 앞에 오는 경우는 없습니다.</p>
</li>
<li><p>&quot; + 3xx + + x7 + &quot;와 같은 잘못된 입력은 주어지지 않습니다.</p>
</li>
<li><p>0으로 시작하는 수는 없습니다.</p>
</li>
<li><p>문자와 숫자 사이의 곱하기는 생략합니다.</p>
</li>
<li><p>polynomial에는 일차 항과 상수항만 존재합니다.</p>
</li>
<li><p>계수 1은 생략합니다.</p>
</li>
<li><p>결괏값에 상수항은 마지막에 둡니다.</p>
</li>
<li><p>0 &lt; polynomial의 길이 &lt; 50</p>
</li>
</ul>
<br>

<p><strong>입출력 예</strong></p>
<table>
<thead>
<tr>
<th align="center">keyinput</th>
<th align="center">result</th>
</tr>
</thead>
<tbody><tr>
<td align="center">&quot;3x + 7 + x&quot;</td>
<td align="center">&quot;4x + 7&quot;</td>
</tr>
<tr>
<td align="center">&quot;x + x + x&quot;</td>
<td align="center">&quot;3x&quot;</td>
</tr>
</tbody></table>
<ul>
<li><p>&quot;3x + 7 + x&quot;에서 동류항끼리 더하면 &quot;4x + 7&quot;입니다.</p>
</li>
<li><p>&quot;x + x + x&quot;에서 동류항끼리 더하면 &quot;3x&quot;입니다.</p>
</li>
</ul>
<hr>
<h3 id="나의-출력-코드">나의 출력 코드</h3>
<pre><code class="language-js">function solution(polynomial) {
    let value = polynomial.split(&#39; + &#39;)

    let x = 0;
    let c = 0;

    for(let i =0; i&lt;value.length; i++){
        let item = value[i]

        if(item[item.length-1] !== &#39;x&#39;){
            c += Number(item)
        } 
        else {
            //x 일떄
            const num = item.split(&#39;x&#39;)[0]
            if(num === &#39;&#39;){
                x += 1
            }else{
               x += Number(num)

          } 
        }
    }

    let answer = &#39;&#39;
    if(x === 1 ) {
        answer += &#39;x&#39;
    }
    if (x&gt;1){
        answer +=`${x}x`
    }
    if(x===0 &amp;&amp; c &gt; 0){
        answer += c
    }
    else if(c &gt; 0){
        answer +=` + ${c}`
    }

    return answer
}</code></pre>
<p>💡 <strong>입/출력 접근</strong></p>
<ol>
<li>polynomial : &quot;3x + 7 + x&quot; 공백을 포함한 문자열 식인 해당 입력 값을 split(&quot; + &quot;)을 통해 +를 포함한 공백을 제거한 배열 반환.
=&gt; [&quot;3x&quot;,&quot;7&quot;,&quot;x&quot;]</li>
<li>if 조건을 통해 x를 포함한 항인지 아닌지 구별.
2-1. x가 아니면 상수항에다 추출된 문자열 넘버를 형변환하여 재할당.
2-2. x이면 문자&#39;x&#39;를 나누어 필요한 숫자를 추출 그러나 x의 값이 하나만 존재할 경우와 아닐 경우를 고려하여 if조건 추가<ol start="3">
<li>return할 answer 자체를 선언하여 반환해야할 문자열 식을 조건을 통해 할당
3-1. x가 1일 경우 answer의 x 부분은 숫자 없이 문자만 존재
3-2. x &gt; 1일 경우 저장 된 x의 값을 템플릿 리터럴(백틱으로 감싼 문자열)을 통해 해당 값 호출
3-3. x===0 &amp;&amp; c &gt;0 일 경우  answer는 c 값만 존재
3-4. c &gt; 0도 포함일 경우 저장된 c의 값을 호출하여 식을 마무리하여 리턴.</li>
</ol>
</li>
</ol>
]]></description>
        </item>
        <item>
            <title><![CDATA[🟣 [엘리스 프리트랙] 문제 정리]]></title>
            <link>https://velog.io/@woo_7i/%EB%AC%B8%EC%A0%9C%EC%A0%95%EB%A6%AC</link>
            <guid>https://velog.io/@woo_7i/%EB%AC%B8%EC%A0%9C%EC%A0%95%EB%A6%AC</guid>
            <pubDate>Mon, 31 Jul 2023 13:12:46 GMT</pubDate>
            <description><![CDATA[<h3 id="엘리스트랙-프리트랙-과정-문제-1">엘리스트랙 프리트랙 과정 문제 #1</h3>
<blockquote>
<p><strong>[엘리스 프리트랙]</strong>  : 구슬 꾸러미</p>
</blockquote>
<p><strong>문제 설명</strong> 
엘리스 토끼는 구슬 장사를 위해 구슬을 꾸러미에 담아 포장을 하고 있습니다. 엘리스 토끼가 준비한 구슬은 색상별로 무게가 모두 다르며 구슬 꾸러미 또한 구슬을 담아낼 수 있는 무게가 모두 달라 최소한의 구슬 개수를 활용해 꾸러미를 채우려고 합니다.</p>
<p>색깔과 무게가 다른 3가지 종류의 구슬이 무제한으로 주어집니다.</p>
<p>구슬    무게
빨간 구슬    250g
파란 구슬    40g
흰 구슬    10g</p>
<p>예를 들어, 300 300g의 꾸러미를 만들기 위해서는 빨간 구슬 1개, 파란 구슬 1개, 흰 구슬 
1개로 최소 3개의 구슬이 필요합니다.
<br></p>
<p><strong>제한사항</strong></p>
<ul>
<li><p>input 매개변수로부터 구슬 꾸러미의 무게를 입력받고 꾸러미를 만드는 데 사용되는 최소 구슬의 수를 출력하세요.
(1≤input≤10,000)</p>
</li>
<li><p>만약 무게에 맞추어 꾸러미를 만들 수 없는 경우에는 -1을 출력하세요.</p>
</li>
</ul>
<p><strong>입출력 예</strong></p>
<table>
<thead>
<tr>
<th align="center">입력</th>
<th align="center">출력</th>
</tr>
</thead>
<tbody><tr>
<td align="center">300</td>
<td align="center">3</td>
</tr>
<tr>
<td align="center">550</td>
<td align="center">4</td>
</tr>
<tr>
<td align="center">65</td>
<td align="center">-1</td>
</tr>
</tbody></table>
<hr>
<h3 id="나의-풀이">나의 풀이</h3>
<pre><code class="language-js">// 지시사항을 참고하여 solution 함수 안에 코드를 작성하세요.
function solution(input) {
  let bead = [
    { color: &#39;redBead&#39;, weight: 250 },
    { color: &#39;whiteBead&#39;, weight: 40 },
    { color: &#39;blueBead&#39;, weight: 10 },
  ];
  let count = 0;

  for (let i = 0; i &lt; bead.length; i++) {
    let needBead = bead[i];
    while (input &gt;= needBead.weight) {
      input -= needBead.weight;
      count += 1;
    }
  }
  if (input !== 0) count = -1;

  return count;
}
</code></pre>
<h4 id="풀이-접근">풀이 접근</h4>
<ol>
<li>각 구슬 별 목록과 무게의 객체를 배열로 만듬</li>
<li>배열을 순회하면서 객체 속 목록을 꺼냄</li>
<li>반복 안에 while을 중복하여 각 구슬 무게가 input만큼 필요한 최소 무게를 구할 때까지 순회</li>
<li>input에 필요한 무게 값만큼 count를 더해줘 각 무게별로 몇 개씩 필요한지 구함</li>
</ol>
<hr>
<h3 id="엘리스트랙-프리트랙-과정-문제-2">엘리스트랙 프리트랙 과정 문제 #2</h3>
<blockquote>
<p><strong>[엘리스 프리트랙]</strong>  : 마천루</p>
</blockquote>
<p><strong>문제 설명</strong> 
코더랜드의 유능한 건축가 엘리스 토끼는 모자장수로부터 새로운 사업을 제안 받았습니다.</p>
<p>바로 코더랜드 한가운데 마천루를 지어 관광객을 유치하는 사업이였습니다.</p>
<p>지시사항을 참고하여 코드를 작성하세요.
<br></p>
<p><strong>제한사항</strong></p>
<ul>
<li><p>마천루의 높이를 input 매개변수로부터 입력받아 아래의 조건을 참고하여 사용자가 입력한 만큼의 높이를 가지는 마천루를 출력하세요.</p>
</li>
<li><p>출력할 값은 solution 함수 안에서 return 해주세요.</p>
</li>
</ul>
<p><strong>입출력 예</strong></p>
<table>
<thead>
<tr>
<th align="center">입력</th>
<th align="center">출력</th>
</tr>
</thead>
<tbody><tr>
<td align="center">3</td>
<td align="center">*</td>
</tr>
<tr>
<td align="center"></td>
<td align="center">-**</td>
</tr>
<tr>
<td align="center"></td>
<td align="center">--***</td>
</tr>
</tbody></table>
<hr>
<h3 id="나의-풀이-1">나의 풀이</h3>
<pre><code class="language-js">// 지시사항을 참고하여 solution 함수 안에 코드를 작성하세요.
function solution(input) {
  let star = &#39;&#39;;
  for (let i = 1; i &lt;= input; i++) {
    for (let j = 0; j &lt; i; j++) {
      if (j &gt;= 5) continue;
      star += &#39;*&#39;;
    }
    if (i !== input) {
      // 마지막 반복이 아닌 경우에만 개행 문자 추가
      star += &#39;\n&#39;;
    }
  }
  return star;
}</code></pre>
<h4 id="풀이-접근-1">풀이 접근</h4>
<ol>
<li>반복해서 별을 찍어내는 코드와 똑같지만 길이가 5 이상되면</li>
<li>더이상 별을 추가하지 않고 길이 5만큼의 별을 똑같이 쌓아가면 됨.</li>
<li>마지막 반복에서 개행이 추가 됐었어서 조건을 통해 마지막 반복에는 개행을 추가하지 않기로 함.</li>
</ol>
<hr>
<h3 id="엘리스트랙-프리트랙-과정-문제-3">엘리스트랙 프리트랙 과정 문제 #3</h3>
<blockquote>
<p><strong>[엘리스 프리트랙]</strong>  : 반쪽짜리 피라미드</p>
</blockquote>
<p><strong>문제 설명</strong> 
엘리스 토끼는 사용자가 입력한 숫자만큼 높이를 가지는 반쪽 피라미드를 만들어주는 프로그램을 만들려고 합니다.</p>
<p>지시사항을 참고하여 코드를 작성하세요.
<br></p>
<p><strong>제한사항</strong>
*num 매개변수에서 자연수를 입력받습니다. 입력된 숫자만큼 높이를 가지는 반쪽 피라미드를 출력하세요.</p>
<p><strong>입출력 예</strong></p>
<table>
<thead>
<tr>
<th align="center">입력</th>
<th align="center">출력</th>
</tr>
</thead>
<tbody><tr>
<td align="center">3</td>
<td align="center">--*</td>
</tr>
<tr>
<td align="center"></td>
<td align="center">-**</td>
</tr>
<tr>
<td align="center"></td>
<td align="center">***</td>
</tr>
</tbody></table>
<hr>
<h3 id="나의-풀이-2">나의 풀이</h3>
<pre><code class="language-js">function solution(num) {
  let result = &#39;&#39;;

  for (let i = 1; i &lt;= num; i++) {
    let answer = &#39;&#39;;
    let space = &#39;&#39;;

    for (let j = 0; j &lt; num - i; j++) {
      space += &#39; &#39;;
    }

    for (let k = 0; k &lt; i; k++) {
      answer += &#39;*&#39;;
    }

    result += space + answer;
    if (i &lt; num) {
      result += &#39;\n&#39;;
    }
  }
  return result;
}</code></pre>
<h4 id="풀이-접근-2">풀이 접근</h4>
<ol>
<li>반쪽 공간을 만들 space 변수를 생성.</li>
<li>두개의 반복문을 통해 빈공간을 생성할 반복문, 별들을 찍어내는 반복문을 통해 합쳐내면 됨.</li>
</ol>
<hr>
<h3 id="엘리스트랙-프리트랙-과정-문제-4">엘리스트랙 프리트랙 과정 문제 #4</h3>
<blockquote>
<p><strong>[엘리스 프리트랙]</strong>  : 겹치는 구간 찾기</p>
</blockquote>
<p><strong>문제 설명</strong> 
수직선 상에 A 구간과 B 구간이 있습니다.</p>
<p>예를들어 A 구간은 3 이상 7 이하에 해당하며, B 구간은 5 이상 9 이하에 해당한다고 가정합니다.</p>
<p>그렇다면 5 이상 7 이하의 구간은 A 구간이면서 동시에 B 구간이 됩니다.</p>
<p>위와 같이, 두 구간의 범위가 주어졌을 때 두 구간이 겹치는 범위를 출력하세요.</p>
<p>두 구간이 겹치지 않는 경우는 별도로 처리해야 합니다.
<br></p>
<p><strong>제한사항</strong></p>
<ul>
<li><p>네 줄에 걸쳐 0이상의 정수가 줄바꿈을 포함한 문자열 형태로 매개변수 input에 받아집니다.</p>
<p>  첫 번째 줄에는 구간 A의 최솟값이 입력됩니다.
  두 번째 줄에는 구간 A의 최댓값이 입력됩니다
  세 번째 줄에는 구간 B의 최솟값이 입력됩니다
  네 번째 줄에는 구간 B의 최댓값이 입력됩니다.
  각 구간을 나타내는 최솟값과 최댓값은 항상 정수입니다.
  구간 A와 B, 두 구간에 겹치는 부분의 최솟값과 최댓값을 공백으로 구분하여 출력하세요.</p>
</li>
<li><p>최솟값과 최댓값이 동일한 경우 해당 구간은 겹치는 구간에 포함됩니다.
만약 두 구간이 겹치지 않는다면 X를 출력해 주세요.</p>
</li>
<li><p>각 구간을 배열에 담아 solution 함수 안에서 return 하세요.</p>
</li>
</ul>
<p><strong>입출력 예</strong></p>
<table>
<thead>
<tr>
<th align="center">입력</th>
<th align="center">출력</th>
</tr>
</thead>
<tbody><tr>
<td align="center">3</td>
<td align="center"></td>
</tr>
<tr>
<td align="center">7</td>
<td align="center">[5, 7]</td>
</tr>
<tr>
<td align="center">5</td>
<td align="center"></td>
</tr>
<tr>
<td align="center">9</td>
<td align="center"></td>
</tr>
<tr>
<td align="center"></td>
<td align="center"></td>
</tr>
<tr>
<td align="center">0</td>
<td align="center"></td>
</tr>
<tr>
<td align="center">10</td>
<td align="center">[3, 8]</td>
</tr>
<tr>
<td align="center">3</td>
<td align="center"></td>
</tr>
<tr>
<td align="center">8</td>
<td align="center"></td>
</tr>
</tbody></table>
<hr>
<h3 id="나의-풀이-3">나의 풀이</h3>
<pre><code class="language-js">// 지시사항을 참고하여 solution 함수 안에 코드를 작성하세요.
let splitString = function (word, seperator) {
  let result = [];
  let currentWord = &#39;&#39;;

  if (seperator === &#39;&#39;) {
    // separator가 빈 문자열인 경우, 각 글자를 배열에 담음
    for (let i = 0; i &lt; word.length; i++) {
      result.push(word[i]);
    }
  } else {
    for (let i = 0; i &lt; word.length; i++) {
      if (word[i] === seperator) {
        result.push(currentWord);
        currentWord = &#39;&#39;;
      } else {
        currentWord += word[i];
      }
    }
    result.push(currentWord);
  }

  return result;
};

let range = function (min, max) {
  let ansewr = [];
  for (min; min &lt;= max; min++) {
    ansewr.push(min);
  }
  return ansewr;
};

function solution(input) {
  let inputSplit = splitString(input, &#39;\n&#39;);
  let rangeA = range(+inputSplit[0], +inputSplit[1]);
  let rangeB = range(+inputSplit[2], +inputSplit[3]);

  let overlap = [];

  for (let i = 0; i &lt; rangeA.length; i++) {
    for (let j = 0; j &lt; rangeB.length; j++) {
      if (rangeA[i] === rangeB[j]) overlap.push(rangeA[i]);
    }
  }

  if (overlap.length === 0) return &#39;X&#39;;
  else return [Math.min(...overlap), Math.max(...overlap)];
}</code></pre>
<h4 id="풀이-접근-3">풀이 접근</h4>
<ol>
<li>split 메서드를 사용하지 않고 구현을 통해 &#39;\n&#39; 개행 문자를 제거.</li>
<li>range 함수를 통해서 각 input 값에 해당하는 범위의 배열 반환</li>
<li>변수 rangeA, rangeB 설정하여 각 범위에 맞는 배열 반환.</li>
<li>반복 중첩을 통해 겹치는 부분 overlap 배열에 push</li>
<li>return 값으로 Math 메소드를 적용시키기 위해 스프레드 문법 적용.</li>
</ol>
<hr>
<h3 id="엘리스트랙-프리트랙-과정-문제-5">엘리스트랙 프리트랙 과정 문제 #5</h3>
<blockquote>
<p><strong>[엘리스 프리트랙]</strong>  : 8은 특별해!</p>
</blockquote>
<p><strong>문제 설명</strong> 
가로, 세로로 가운데를 갈라도 모두 같은 모양인 8을 좋아하는 엘리스 토끼는 1부터 10000까지 8이라는 숫자가 몇 번 나오는지 알아보려고 해요!</p>
<p>지시사항을 참고하여 코드를 작성하세요.
<br></p>
<p><strong>제한사항</strong></p>
<ul>
<li>1부터 10,000까지의 수 중 8의 개수를 세어 함수 안에서 리턴하세요.</li>
</ul>
<p><strong>입출력 예</strong></p>
<table>
<thead>
<tr>
<th align="center">입력</th>
<th align="center">출력</th>
</tr>
</thead>
<tbody><tr>
<td align="center">// 범위를 1~20로 가정했을 때 8의 개수// 8, 18</td>
<td align="center">2</td>
</tr>
</tbody></table>
<hr>
<h3 id="나의-풀이-4">나의 풀이</h3>
<pre><code class="language-js">// 지시사항을 참고하여 solution 함수 안에 코드를 작성하세요.
function solution() {
  let count = 0;

  for (let i = 1; i &lt; 10000; i++) {
    let currentNum = i;
    while (currentNum &gt; 0) {
      if (currentNum % 10 === 8) count += 1;
      currentNum = Math.floor(currentNum / 10); // currentNum을 업데이트 해줘야함.
    }
  }
  return count;
}</code></pre>
<h4 id="풀이-접근-4">풀이 접근</h4>
<ol>
<li>제한사항에서 10000까지 반복해야 하는 for문 조건을 생성</li>
<li>while을 통해 현재 값이 8이 있는지 없는지 파악하기 위해 10을 나눈 뒤 나머지는 버리는 형식으로 계속 업데이트하여 1의 자리수가 될 때까지 반복. </li>
</ol>
<hr>
<h3 id="엘리스트랙-프리트랙-과정-문제-6">엘리스트랙 프리트랙 과정 문제 #6</h3>
<blockquote>
<p><strong>[엘리스 프리트랙]</strong>  : 암호문 해석하기</p>
</blockquote>
<p><strong>문제 설명</strong> 
에니그마(Enigma, 수수께끼)는 독일군이 전장에서 사용했던 암호 생성 장치입니다.</p>
<p>독일어 알파벳 각각에 대하여 다른 알파벳에 임의로 대응시킨 다음, 이렇게 대응된 알파벳으로 전신 부호를 발송했습니다.</p>
<p>예를 들어 a는 p, b는 q, c는 r에 대응시켜 암호화한 전신을 보낼 때 ‘abc’는 ‘pqr’로 전달됩니다. 해독 코드가 담긴 문서는 사람을 써서 반대편에 미리 전달해두고, 이것을 참고해서 전신을 해독했습니다.</p>
<p>에니그마는 각 알파벳이 대응하는 다른 알파벳의 세트에 따라 같은 단어도 다른 코드로 변환합니다.</p>
<p>암호의 알파벳을 키로, 대응하는 알파벳을 값으로 저장한 두 개의 객체 signal1 과 signal2가 있습니다.</p>
<p>암호문의 형태는 다음과 같습니다.</p>
<pre><code>01011 eowxvqp</code></pre><p>우선 01011은 5개의 0과 1로 구성되어 있으므로 암호문이 5개의 알파벳으로 구성된 암호문이라는 것을 알 수 있습니다.</p>
<p>따라서 이 암호문은 5번째 알파벳인 v까지만 해석하며, 6번째 알파벳인 q부터는 해석하지 않고 버립니다.</p>
<p>앞에 0과 1은 같은 자리의 알파벳을 각각 signal1을 이용하여 해석할지, signal2를 이용하여 해석할지를 의미합니다.</p>
<p>위 예시에서 0에 대응하는 e, w는 signal1을 이용하여 해석하고 1에 대응하는 o, x, v는 signal2를 이용하여 해석합니다.</p>
<p>signal1에서 e와 w는 각각 e와 i에 대응하며, signal2에서 o, x, v는 각각 l,c,e에 대응합니다.</p>
<p>따라서 예시의 암호문을 해석하면 elice가 되며 이를 출력하시면 정답입니다.</p>
<p>이처럼 암호문을 문자열로 입력받으면 이를 원문으로 해석한 문자열을 출력하는 프로그램을 완성하세요.
<br></p>
<p><strong>제한사항</strong></p>
<ul>
<li><p>해석해야할 암호문 매개변수 code를 입력 받습니다.</p>
</li>
<li><p>암호문을 해석한 후 solution 함수 안에서 return 해주세요.</p>
</li>
</ul>
<p><strong>입출력 예</strong></p>
<table>
<thead>
<tr>
<th align="center">입력</th>
<th align="center">출력</th>
</tr>
</thead>
<tbody><tr>
<td align="center">01011 eowxvqp</td>
<td align="center">elice</td>
</tr>
<tr>
<td align="center">111 zmgaaw</td>
<td align="center">ant</td>
</tr>
</tbody></table>
<hr>
<h3 id="나의-풀이-5">나의 풀이</h3>
<pre><code class="language-js">// 암호의 알파벳을 키로, 대응하는 원문의 알파벳을 값으로 저장한 딕셔너리입니다.
var signal1 = {
  a: &#39;n&#39;,
  b: &#39;d&#39;,
  c: &#39;a&#39;,
  d: &#39;b&#39;,
  e: &#39;e&#39;,
  f: &#39;l&#39;,
  g: &#39;j&#39;,
  h: &#39;o&#39;,
  i: &#39;z&#39;,
  j: &#39;u&#39;,
  k: &#39;y&#39;,
  l: &#39;v&#39;,
  m: &#39;w&#39;,
  n: &#39;q&#39;,
  o: &#39;x&#39;,
  p: &#39;r&#39;,
  q: &#39;p&#39;,
  r: &#39;f&#39;,
  s: &#39;g&#39;,
  t: &#39;t&#39;,
  u: &#39;m&#39;,
  v: &#39;h&#39;,
  w: &#39;i&#39;,
  x: &#39;c&#39;,
  y: &#39;k&#39;,
  z: &#39;s&#39;,
};

var signal2 = {
  a: &#39;z&#39;,
  b: &#39;y&#39;,
  c: &#39;x&#39;,
  d: &#39;w&#39;,
  e: &#39;v&#39;,
  f: &#39;u&#39;,
  g: &#39;t&#39;,
  h: &#39;s&#39;,
  i: &#39;r&#39;,
  j: &#39;q&#39;,
  k: &#39;p&#39;,
  l: &#39;o&#39;,
  m: &#39;n&#39;,
  n: &#39;m&#39;,
  o: &#39;l&#39;,
  p: &#39;k&#39;,
  q: &#39;j&#39;,
  r: &#39;i&#39;,
  s: &#39;h&#39;,
  t: &#39;g&#39;,
  u: &#39;f&#39;,
  v: &#39;e&#39;,
  w: &#39;d&#39;,
  x: &#39;c&#39;,
  y: &#39;b&#39;,
  z: &#39;a&#39;,
};

let splitMehod = function (word, seperator) {
  let result = [];
  let currentWord = &#39;&#39;;

  if (seperator === &#39;&#39;) {
    for (let i = 0; i &lt; word.length; i++) {
      result.push(word[i]);
    }
  } else {
    for (let i = 0; i &lt; word.length; i++) {
      if (word[i] === seperator) {
        result.push(currentWord);
        currentWord = &#39;&#39;;
      } else {
        currentWord += word[i];
      }
    }
    result.push(currentWord);
  }
  return result;
};

// 지시사항을 참고하여 solution 함수 안에 코드를 작성하세요.
function solution(code) {
  let codeSplit = splitMehod(code, &#39; &#39;);
  let codeNum = codeSplit[0];
  let interpritChar = codeSplit[1];

  let answer = &#39;&#39;;
  for (let i = 0; i &lt; codeNum.length; i++) {
    if (codeNum[i] === &#39;0&#39;) {
      answer += signal1[interpritChar[i]];
    } else {
      answer += signal2[interpritChar[i]];
    }
  }
  return answer;
}
</code></pre>
<h4 id="풀이-접근-5">풀이 접근</h4>
<ol>
<li>공백을 기준으로 입력 값 첫 번째 부분의 코드를 해석할 수 있게 연관된 두 객체 존재.</li>
<li>공백을 기준을 문자열을 나누어 배열로 반환하고 싶기에 split 메소드 구현</li>
<li>해석해야 할 코드와 문자를 개별 변수에 저장</li>
<li>조건을 통해 codeNum의 숫자에 맞게 객체에 존재하는 프로퍼티 값을 answer에 더함.</li>
</ol>
<hr>
<h3 id="엘리스트랙-프리트랙-과정-문제-7">엘리스트랙 프리트랙 과정 문제 #7</h3>
<blockquote>
<p><strong>[엘리스 프리트랙]</strong>  : 문자의 빈도 조사하기.</p>
</blockquote>
<p><strong>문제 설명</strong> 
문자열은 하나이상의 문자들로 구성되어 있습니다. 영어 문장의 경우 a부터 z까지의 알파벳으로 구성되어 있습니다.</p>
<p>이런 영어문장에서 알파벳별로 갯수를 조사하는 자바스크립트 프로그램을 제작하려고 합니다.</p>
<p>지시사항에 맞춰 프로그램을 완성하세요.</p>
<p>우리는 강의에서 메서드에 대해서 배웠습니다. 강의에서 배운 메서드 외에도 여러가지 편리한 메서드가 존재합니다.</p>
<p>강의에서 배우지 않은 새로운 메서드를 힌트를 보고 활용해보세요.
<br></p>
<p><strong>제한사항</strong></p>
<ul>
<li><p>str 매개변수로 부터 문자열을 입력받습니다. (문자열에는 알파벳 및 공백만 포함됩니다.)</p>
<pre><code>  My name is Elice</code></pre></li>
<li><p>모든 문자를 소문자로 변환합니다.</p>
<pre><code>  my name is elice</code></pre></li>
<li><p>각 알파벳이 등장한 횟수를 alpha_cnt에 기록합니다.</p>
</li>
<li><p>solution 함수 안에서 alpha_cnt 객체를 return 하세요.</p>
</li>
</ul>
<p><strong>입출력 예</strong></p>
<table>
<thead>
<tr>
<th align="center">출력</th>
</tr>
</thead>
<tbody><tr>
<td align="center">{ m: 2, y: 1, n: 1, a: 1, e: 3, i: 2, s: 1, l: 1, c: 1 }</td>
</tr>
</tbody></table>
<hr>
<h3 id="나의-풀이-6">나의 풀이</h3>
<pre><code class="language-js">let splitMethod = function (word, seperater) {
  let result = [];
  let currentWord = &#39;&#39;;

  if (seperater === &#39;&#39;) {
    for (let i = 0; i &lt; word.length; i++) {
      result.push(word[i]);
    }
  } else {
    for (let i = 0; i &lt; word.length; i++) {
      if (word[i] === seperater) {
        result.push(currentWord);
        currentWord = &#39;&#39;;
      } else {
        currentWord += word[i];
      }
    }
    result.push(currentWord);
  }

  return result;
};

let lowCaseAlpa = function (arr) {
  let result = [];

  for (let i = 0; i &lt; arr.length; i++) {
    result.push(arr[i].toLowerCase());
  }
  return result;
};

let theCharLine = function (arr) {
  let result = &#39;&#39;;
  for (let i = 0; i &lt; arr.length; i++) {
    result += arr[i];
  }
  return result;
};

// 지시사항을 참고하여 solution 함수 안에 코드를 작성하세요.
function solution(str) {
  let strSplit = splitMethod(str, &#39; &#39;);
  let lowCase = lowCaseAlpa(strSplit);
  let theLine = theCharLine(lowCase);

  let answer = {};
  for (let i = 0; i &lt; theLine.length; i++) {
    let lineItem = theLine[i];

    // 존재하는지 안 하는지에 대한 조건 여부.
    if (!answer[lineItem]) {
      answer[lineItem] = 1;
    } else answer[lineItem] += 1;
  }
  return answer;
}
</code></pre>
<h4 id="풀이-접근-6">풀이 접근</h4>
<ol>
<li>각 공백기준으로 문자들을 배열로 반환</li>
<li>반환된 배열들 순회하여 소문자로 변환</li>
<li>배열을 하나의 문자열로 반환.</li>
<li>answer 객체를 만들어 for반복을 통해 answer에다 속성부여.</li>
<li>조건을 통해 해당 속성이 존재하지 않는다면 1을 더하고 else면 +=1을 카운트함.</li>
</ol>
<hr>
<h3 id="엘리스트랙-프리트랙-과정-문제-8">엘리스트랙 프리트랙 과정 문제 #8</h3>
<blockquote>
<p><strong>[엘리스 프리트랙]</strong>  : 당근 탐지기</p>
</blockquote>
<p><strong>문제 설명</strong> 
땅 속에 숨겨져 있는 당근을 찾기 좋아하는 엘리스 토끼는 당근을 탐지할 수 있는 당근 탐지기를 가지고 왼쪽 혹은 오른쪽으로만 갈 수 있는 길이가 5인 길 어디인가에 떨어졌습니다.</p>
<p>예를 들어 아래와 같이 5칸으로 구성된 길이 있고 O은 당근이 있는 곳, X은 당근이 없는 곳이며 엘리스 토끼가 왼쪽에서 세번째 칸에 떨어졌다고 가정합니다. 이때 왼쪽 끝으로 이동하게 되면 총 1개의 당근을 획득할 수 있으며 오른쪽으로 이동한 경우 2개의 당근을 획득할 수 있습니다.</p>
<p>| ||
| :---:|:---:|:---:|:---:|:---:|
|O|X|X|O|O|
O와 X는 알파벳 대문자 O, X를 의미합니다.
<br></p>
<p><strong>제한사항</strong></p>
<ul>
<li><p>매개변수 a에서 O, X를 받습니다. 매개변수 b에서는 위치 값인 숫자를 받습니다.</p>
</li>
<li><p>떨어진 위치를 기준으로 당근을 최대한 많이 획득할 수 있는 방향(왼쪽, 오른쪽)을 출력하세요.</p>
</li>
<li><p>왼쪽과 오른쪽의 당근의 수가 동일한 경우 동일을 출력하세요.</p>
</li>
<li><p>출력은 solution 함수 안에서 return 하세요.</p>
</li>
</ul>
<p><strong>입출력 예</strong></p>
<table>
<thead>
<tr>
<th align="center">입력</th>
<th align="center">출력</th>
</tr>
</thead>
<tbody><tr>
<td align="center">&quot;O X X O O&quot;, 3</td>
<td align="center">오른쪽</td>
</tr>
</tbody></table>
<hr>
<h3 id="나의-풀이-7">나의 풀이</h3>
<pre><code class="language-js">let splitMethod = function (word, seperator) {
  let result = [];
  let currentWord = &#39;&#39;;

  if (seperator === &#39;&#39;) {
    for (let i = 0; i &lt; word.length; i++) {
      result.push(word[i]);
    }
  } else {
    for (let i = 0; i &lt; word.length; i++) {
      if (word[i] === seperator) {
        result.push(currentWord);
        currentWord = &#39;&#39;;
      } else {
        currentWord += word[i];
      }
    }
    result.push(currentWord);
  }
  return result;
};

// 지시사항을 참고하여 solution 함수 안에 코드를 작성하세요.
function solution(a, b) {
  let splitOX = splitMethod(a, &#39; &#39;);

  let leftCount = 0;
  for (let i = b-1; i &gt;= 0; i--) {
    if (splitOX[i] === &#39;O&#39;) leftCount += 1;
  }

  let rightCount = 0;
  for (let i = b-1; i &lt; splitOX.length; i++) {
    if (splitOX[i] === &#39;O&#39;) rightCount += 1;
  }


  return leftCount &gt; rightCount ? &#39;왼쪽&#39; : (leftCount &lt; rightCount ? &#39;오른쪽&#39; : &#39;동일&#39;);
}
</code></pre>
<h4 id="풀이-접근-7">풀이 접근</h4>
<ol>
<li>OX 문자열 공백 기준으로 나누어 배열로 반환</li>
<li>함수 인자 b의 값을 기준으로 for 조건 i의 값 형성</li>
<li>당근이 몇개 존재하는지 각 변수에 카운트 값 저장</li>
<li>삼항연산자의 중복으로 세가지 return 값 조건 설정</li>
</ol>
<hr>
<h3 id="엘리스트랙-프리트랙-과정-문제-9">엘리스트랙 프리트랙 과정 문제 #9</h3>
<blockquote>
<p><strong>[엘리스 프리트랙]</strong>  : 더치페이 계산하기</p>
</blockquote>
<p><strong>문제 설명</strong> 
A, B, C 세명의 친구는 점심을 함께 먹고 각자 먹은 메뉴에 따라 계산하기로 했습니다.</p>
<p>세명의 친구가 각각 메뉴를 하나씩만 주문했다면 쉽게 계산이 가능했겠지만, B는 2개의 메뉴를 주문하고 C는 3개를 주문했습니다.</p>
<p>거기에 세명이 함께 먹는 사이드메뉴까지 포함되어 있어서 이를 반영해서 각자 지불할 금액을 계산하는 프로그램을 만드려고 합니다.</p>
<p>지시사항을 참고하여 A, B, C 가 각각 지불해야하는 금액을 출력하는 프로그램을 제작하세요. 
<br></p>
<p><strong>제한사항</strong></p>
<ul>
<li><p>menu 라는 객체에 메뉴명을 키로, 메뉴의 가격을 값으로 저장되어 있습니다.</p>
</li>
<li><p>이들이 주문한 내역은 먹은사람, 메뉴이름, 수량의 형태로 입력받습니다. 만약 세명이 다같이 먹은 메뉴라면 K로 표시합니다.</p>
</li>
<li><p>각자 지불할 금액을 계산하여 객체에 담아 출력합니다.</p>
</li>
<li><p>출력할 값은 solution 함수에서 return 해주세요. </p>
</li>
</ul>
<p><strong>입출력 예</strong></p>
<table>
<thead>
<tr>
<th align="center">입력</th>
<th align="center">출력</th>
</tr>
</thead>
<tbody><tr>
<td align="center">[</td>
<td align="center"></td>
</tr>
<tr>
<td align="center">[ &quot;A&quot;, &quot;라면&quot;, 1],</td>
<td align="center"></td>
</tr>
<tr>
<td align="center">[ &quot;B&quot;, &quot;김밥&quot;, 2],</td>
<td align="center"></td>
</tr>
<tr>
<td align="center">[ &quot;B&quot;, &quot;떡볶이&quot;, 1],</td>
<td align="center">{ A: 7000, B: 10000, C: 2000 }</td>
</tr>
<tr>
<td align="center">[ &quot;K&quot;, &quot;튀김세트&quot;, 1],</td>
<td align="center"></td>
</tr>
<tr>
<td align="center">[ &quot;C&quot;, &quot;콜라&quot;, 1 ]</td>
<td align="center"></td>
</tr>
<tr>
<td align="center">];</td>
<td align="center"></td>
</tr>
</tbody></table>
<hr>
<h3 id="나의-풀이-8">나의 풀이</h3>
<pre><code class="language-js">let theObject = function (arr) {
  let answer = [];

  for (let i = 0; i &lt; arr.length; i++) {
    for (let j = 0; j &lt; 1; j++) {
      let payCount = {
        name: arr[i][0],
        food: arr[i][1],
        foodCnt: arr[i][2],
      };
      answer.push(payCount);
    }
  }
  return answer;
};

function solution(input) {
  var menu = {
    떡볶이: 5000,
    김밥: 2000,
    튀김세트: 3000,
    순대: 4000,
    라면: 6000,
    콜라: 1000,
    사이다: 1000,
  };
  theObject(input);

  let answer = {
    A: 0,
    B: 0,
    C: 0,
    K: 0,
  };

  for (let i = 0; i &lt; input.length; i++) {
    let objectName = input[i][0]; // &quot;A&quot;, &quot;B&quot;, &quot;C&quot; 중 하나가 됩니다.
    let foodName = input[i][1];
    let foodCnt = input[i][2];

    answer[objectName] += menu[foodName] * foodCnt;
  }
  if (answer.K) {
    answer.A += Math.floor(answer.K / 3);
    answer.B += Math.floor(answer.K / 3);
    answer.C += Math.floor(answer.K / 3);
  }
  delete answer.K;

  return answer;
}
</code></pre>
<h4 id="풀이-접근-8">풀이 접근</h4>
<ol>
<li>입력값 각 배열에 담긴 이름, 음식, 개수를 객체화 하여 배열로 반환</li>
<li>theObject() 함수로 반환된 배열 객체를 for문을 통해 순환하여
objectName
foodName
foodCnt 변수에 각 객체 속성값에 맞게 저장.</li>
<li>answer 객체에 연관되는 속성에 맞게 가격을 값을 저장</li>
<li>k가 존재하면 제한사항 인원에 맞게 3으로 나눈 가격을 각각 나눔.</li>
<li>마지막으로 k를 삭제하고 </li>
<li>answer 객체 반환</li>
</ol>
<hr>
<h3 id="엘리스트랙-프리트랙-과정-문제-10">엘리스트랙 프리트랙 과정 문제 #10</h3>
<blockquote>
<p><strong>[엘리스 프리트랙]</strong>  : 문자열 데이터 압축하기</p>
</blockquote>
<p><strong>문제 설명</strong> 
데이터를 압축하는 방법으로는 다양한 알고리즘이 존재합니다.</p>
<p>그 중에 Run-length encoding (이하 RLE)은 연속되어 같은 문자가 반복될때 어떤 문자가 몇번 반복되는지로 압축하여 표현하는 방법입니다.</p>
<p>예를 들어, “aaaaaabbbcccccbbbbb” 라는 19개의 문자 데이터는 a가 6번, b가 3번, c가 5번, b가 5번 연속되어 나타납니다. 이는 “a6b3c5b5” 이렇게 8개의 문자로 압축하여 표현할 수 있습니다.</p>
<p>하지만 “aabb” 이렇게 2번 이하로 반복되는 문자는 “a2b2” 이렇게 바꿔서 표현해도 길이는 줄어들지 않기 때문에 이는 그대로 “aabb”로 표현하고자 합니다.</p>
<p>즉, “aaabbccccaabbbb”이런 문자열을 이 알고리즘을 이용하여 압축하면 “a3bbc4aab4” 이렇게 표현할 수 있습니다.</p>
<p>이 알고리즘을 이용하여 ‘A’부터 ‘Z’까지 26개의 대문자 알파벳으로 구성된 문자열을 압축하는 자바스크립트 프로그램을 만들려고 합니다.</p>
<p>지시사항에 따라 프로그램를 완성시키세요.
<br></p>
<p><strong>제한사항</strong></p>
<ul>
<li><p>A부터 Z까지 대문자 알파벳으로만 구성된 문자열을 인자로 받습니다.</p>
</li>
<li><p>이 문자열을 위에서 설명한 RLE 방식으로 압축합니다.</p>
</li>
<li><p>압축된 문자열을 출력합니다.</p>
</li>
<li><p>출력은 solution 함수 안에서 return 하세요.</p>
</li>
</ul>
<p><strong>입출력 예</strong></p>
<table>
<thead>
<tr>
<th align="center">입력</th>
<th align="center">출력</th>
</tr>
</thead>
<tbody><tr>
<td align="center">AAAAABBCCCDDDZZZWW</td>
<td align="center">A5BBC3D3Z3WW</td>
</tr>
</tbody></table>
<hr>
<h3 id="나의-풀이-9">나의 풀이</h3>
<pre><code class="language-js">// 지시사항을 참고하여 solution 함수 안에 코드를 작성하세요.
function solution(str) {
  let upperStr = str.toUpperCase();
  let sameCase = {};

  for (let i = 0; i &lt; upperStr.length; i++) {
    let caseItem = upperStr[i];
    if (!sameCase[caseItem]) {
      sameCase[caseItem] = 1;
    } else {
      sameCase[caseItem] += 1;
    }
  }
  console.log(sameCase); //  { A: 5, B: 2, C: 3, D: 3, Z: 3, W: 2 }

  let outputStr = &#39;&#39;;
  const keys = Object.keys(sameCase);
  console.log(keys); // [ &#39;A&#39;, &#39;B&#39;, &#39;C&#39;, &#39;D&#39;, &#39;Z&#39;, &#39;W&#39; ]

  for (let i = 0; i &lt; keys.length; i++) {
    const key = keys[i];

    outputStr += key;

    if (sameCase[key] &gt; 2) {
      outputStr += sameCase[key];
    } else {
      outputStr += key;
    }
  }

  return outputStr;
}
</code></pre>
<h4 id="풀이-접근-9">풀이 접근</h4>
<ol>
<li>각문자열을 제한사항에 맞게 대문자로 변환</li>
<li>문자 빈도 구했던 방식 처럼 각 문자별 속성을 가진 객체 저장</li>
<li>객체 속성 존재 유무에 따라 카운트를 더함</li>
<li>만들어진 sameCase = { A: 5, B: 2, C: 3, D: 3, Z: 3, W: 2 }</li>
<li>Object.keys()메소드를 통해 객체의 키값을 가진 배열 반환.</li>
<li>keys = [ &#39;A&#39;, &#39;B&#39;, &#39;C&#39;, &#39;D&#39;, &#39;Z&#39;, &#39;W&#39; ]</li>
<li>keys를 순회하여 sameCase에 존재하는 속성 값이 2보다 큰지 조건에 따라 
return 할 outputStr에 문자를 더함.</li>
</ol>
<hr>
<h3 id="엘리스트랙-프리트랙-과정-문제-11">엘리스트랙 프리트랙 과정 문제 #11</h3>
<blockquote>
<p><strong>[엘리스 프리트랙]</strong>  : 괄호의 짝</p>
</blockquote>
<p><strong>문제 설명</strong> 
자바스크립트에서 사용하는 괄호는 다양한 종류가 있습니다. 그 중 [ ], ( ), { }는 자주 사용됩니다.</p>
<p>괄호를 사용할때는 항상 짝이 맞는 것을 확인해야 합니다. 예를 들어 { ( ) [ ] }는 짝이 맞지만 { [ } ] .( ) 는 짝이 맞지 않습니다.</p>
<p>이것을 확인하는 자바스크립트 프로그램을 배열을 활용해서 만들어보려고 합니다.</p>
<p>힌트로 제공하는 내용과 지시사항을 읽고 프로그램을 완성하세요.
<br></p>
<p><strong>제한사항</strong></p>
<ul>
<li><p>영어, 숫자, 사칙연산 기호 +*-/ 그리고 괄호들로 구성된 문장을 입력받습니다.</p>
<pre><code>(a+b[a])+[{(b*e)/(a+q)}]</code></pre></li>
<li><p>문자열에서 괄호가 아닌 문자는 제거합니다.</p>
<pre><code>([])[{()()}]</code></pre></li>
<li><p>배열의 pop()과 push()를 이용해서 괄호의 짝이 맞는지 맞지 않는지를 테스트합니다.</p>
</li>
<li><p>짝이 맞다면 <strong>정상</strong>, 짝이 맞지 않는 부분이 하나라도 있다면 <strong>비정상</strong>이라고 출력합니다. 위 문장은 짝이 맞으므로 <strong>정상</strong>을 출력합니다.</p>
</li>
</ul>
<p><strong>입출력 예</strong></p>
<table>
<thead>
<tr>
<th align="center">입력</th>
<th align="center">출력</th>
</tr>
</thead>
<tbody><tr>
<td align="center">(a+b[a])+[{(b*e)/(a+q)}]</td>
<td align="center">정상</td>
</tr>
</tbody></table>
<hr>
<h3 id="나의-풀이-10">나의 풀이</h3>
<pre><code class="language-js">// 지시사항을 참고하여 solution 함수 안에 코드를 작성하세요.
function solution(string) {
  const stack = [];
  // 여는 괄호와 닫는 괄호의 대응을 정의합니다.
  const bracketsMap = {
    &#39;)&#39;: &#39;(&#39;,
    &#39;]&#39;: &#39;[&#39;,
    &#39;}&#39;: &#39;{&#39;,
  };

  for (let i = 0; i &lt; string.length; i++) {
    const char = string[i];
    if (char === &#39;(&#39; || char === &#39;[&#39; || char === &#39;{&#39;) {
      // 여는 괄호인 경우 스택에 추가합니다.
      stack.push(char);
    } else if (char === &#39;)&#39; || char === &#39;]&#39; || char === &#39;}&#39;) {
      // 닫는 괄호인 경우 스택에서 마지막 요소를 꺼냅니다.
      if (stack.length === 0 || stack.pop() !== bracketsMap[char]) {
        // 스택이 비어있거나 짝이 맞지 않는 경우 false를 반환합니다.
        return &#39;비정상&#39;;
      }
    }
  }

  // 모든 입력값을 처리한 후에 스택이 비어있다면, 괄호 짝이 맞는 것으로 판별합니다.
  return stack.length === 0 ? &#39;정상&#39; : &#39;비정상&#39;;
}</code></pre>
<h4 id="풀이-접근-10">풀이 접근</h4>
<ol>
<li>여는 괄호와 닫는 괄호의 대응을 객체로 정의합니다</li>
<li>여는 괄호인 경우 스택에 추가합니다</li>
<li>닫는 괄호인 경우 스택에서 마지막 요소를 꺼냅니다</li>
<li>닫는 괄호인 경우 스택에서 마지막 요소를 꺼냅니다</li>
<li>스택이 비어있거나 짝이 맞지 않는 경우 false를 반환합니다</li>
<li>모든 입력값을 처리한 후에 스택이 비어있다면, 괄호 짝이 맞는 것으로 판별합니다</li>
</ol>
]]></description>
        </item>
        <item>
            <title><![CDATA[🟣 오늘의 문제 회고]]></title>
            <link>https://velog.io/@woo_7i/%EC%98%A4%EB%8A%98%EC%9D%98-%EB%AC%B8%EC%A0%9C-%ED%9A%8C%EA%B3%A0-on9xwx5z</link>
            <guid>https://velog.io/@woo_7i/%EC%98%A4%EB%8A%98%EC%9D%98-%EB%AC%B8%EC%A0%9C-%ED%9A%8C%EA%B3%A0-on9xwx5z</guid>
            <pubDate>Fri, 02 Jun 2023 04:55:48 GMT</pubDate>
            <description><![CDATA[<h3 id="😭-문제-핥짝-1">😭 문제 핥짝 #1</h3>
<blockquote>
<p><strong>[프로그래머스]</strong> Lv0 : 조건 문자열</p>
</blockquote>
<p><strong>문제 설명</strong> 
문자열에 따라 다음과 같이 두 수의 크기를 비교하려고 합니다.</p>
<p>두 수가 n과 m이라면
&quot;&gt;&quot;, &quot;=&quot; : n &gt;= m
&quot;&lt;&quot;, &quot;=&quot; : n &lt;= m
&quot;&gt;&quot;, &quot;!&quot; : n &gt; m
&quot;&lt;&quot;, &quot;!&quot; : n &lt; m
두 문자열 ineq와 eq가 주어집니다. ineq는 &quot;&lt;&quot;와 &quot;&gt;&quot;중 하나고, eq는 &quot;=&quot;와 &quot;!&quot;중 하나입니다. 그리고 두 정수 n과 m이 주어질 때, n과 m이 ineq와 eq의 조건에 맞으면 1을 아니면 0을 return하도록 solution 함수를 완성해주세요.</p>
<p>암호화된 문자열 cipher를 주고받습니다.
그 문자열에서 code의 배수 번째 글자만 진짜 암호입니다.
문자열 cipher와 정수 code가 매개변수로 주어질 때 해독된 암호 문자열을 return하도록 solution 함수를 완성해주세요.</p>
<p><strong>제한사항</strong></p>
<ul>
<li>1 ≤ n, m ≤ 100</li>
</ul>
<p><strong>입출력 예</strong></p>
<table>
<thead>
<tr>
<th align="center">ineq</th>
<th align="center">eq</th>
<th align="center">n</th>
<th align="center">m</th>
<th align="center">result</th>
</tr>
</thead>
<tbody><tr>
<td align="center">&quot;&lt;&quot;</td>
<td align="center">&quot;=&quot;</td>
<td align="center">20</td>
<td align="center">50</td>
<td align="center">1</td>
</tr>
<tr>
<td align="center">&quot;&gt;&quot;</td>
<td align="center">&quot;!&quot;</td>
<td align="center">41</td>
<td align="center">78</td>
<td align="center">0</td>
</tr>
</tbody></table>
<hr>
<h3 id="나의-풀이">나의 풀이</h3>
<pre><code class="language-js">function solution(ineq, eq, n, m) {
    let answer = 0

 if(ineq == &quot;&lt;&quot; &amp;&amp; eq == &quot;=&quot;) {
            if(n &lt;= m) answer = 1;
        }
        else if(ineq == &quot;&lt;&quot; &amp;&amp; eq == &quot;!&quot;) {
            if(n &lt; m) answer = 1;
        }
        else if(ineq == &quot;&gt;&quot; &amp;&amp; eq == &quot;=&quot;) {
            if(n &gt;= m) answer = 1;
        }
        else if(ineq == &quot;&gt;&quot; &amp;&amp; eq == &quot;!&quot;) {
            if(n &gt; m) answer = 1;
        }
        else answer = 0;

        return answer;

}</code></pre>
<h3 id="다른-사람-풀이">다른 사람 풀이</h3>
<pre><code class="language-js">const operations = {
  &#39;&gt;=&#39;: (n, m) =&gt; n &gt;= m,
  &#39;&lt;=&#39;: (n, m) =&gt; n &lt;= m,
  &#39;&gt;!&#39;: (n, m) =&gt; n &gt; m,
  &#39;&lt;!&#39;: (n, m) =&gt; n &lt; m,
};

function solution(ineq, eq, n, m) {
  const op = operations[ineq + eq];
  return Number(op(n, m));
}</code></pre>
<p>#풀이 이해</p>
<ol>
<li>객체를 통해 문자열 조건을 속성값으로 지정
arrow 함수를 적용시켜 문자열의 조건을 return 하는 객체를 만들어 냄.</li>
</ol>
]]></description>
        </item>
        <item>
            <title><![CDATA[🟣 이전 문제 회고]]></title>
            <link>https://velog.io/@woo_7i/%EC%9D%B4%EC%A0%84-%EB%AC%B8%EC%A0%9C-%ED%9A%8C%EA%B3%A0</link>
            <guid>https://velog.io/@woo_7i/%EC%9D%B4%EC%A0%84-%EB%AC%B8%EC%A0%9C-%ED%9A%8C%EA%B3%A0</guid>
            <pubDate>Sat, 22 Apr 2023 04:57:21 GMT</pubDate>
            <description><![CDATA[<h3 id="😭-문제-핥짝-1">😭 문제 핥짝 #1</h3>
<blockquote>
<p><strong>[프로그래머스]</strong> Lv0 : 암호 해독</p>
</blockquote>
<p><strong>문제 설명</strong> 
군 전략가 머쓱이는 전쟁 중 적군이 다음과 같은 암호 체계를 사용한다는 것을 알아냈습니다.</p>
<p>암호화된 문자열 cipher를 주고받습니다.
그 문자열에서 code의 배수 번째 글자만 진짜 암호입니다.
문자열 cipher와 정수 code가 매개변수로 주어질 때 해독된 암호 문자열을 return하도록 solution 함수를 완성해주세요.</p>
<p><strong>제한사항</strong></p>
<ul>
<li>1 ≤ cipher의 길이 ≤ 1,000</li>
<li>1 ≤ code ≤ cipher의 길이</li>
<li>cipher는 소문자와 공백으로만 구성되어 있습니다.</li>
<li>공백도 하나의 문자로 취급합니다.</li>
</ul>
<p><strong>입출력 예</strong></p>
<table>
<thead>
<tr>
<th align="center">cipher</th>
<th align="center">code</th>
<th align="center">result</th>
</tr>
</thead>
<tbody><tr>
<td align="center">&quot;dfjardstddetckdaccccdegk&quot;</td>
<td align="center">4</td>
<td align="center">&quot;attack&quot;</td>
</tr>
<tr>
<td align="center">&quot;pfqallllabwaoclk&quot;</td>
<td align="center">2</td>
<td align="center">&quot;fallback&quot;</td>
</tr>
</tbody></table>
<hr>
<h3 id="나의-풀이">나의 풀이</h3>
<pre><code class="language-js">function solution(cipher, code) {
  let answer = [];
  // cipher.split(&quot;&quot;).filter((e, i) =&gt; (i + 1) % code === 0);

  for (let i = 0; i &lt; cipher.length; i++) {
    if ((i + 1) % code === 0) answer.push(cipher[i]);
  }

  return answer.join(&quot;&quot;);
}
</code></pre>
<p><strong>상태 접근</strong></p>
<ol>
<li>for 반복을 통해 if 조건의 i 값에 1을 더하여 인덱스 값의 시작을 변경</li>
<li>1번을 통해 배열이 되는 cipher의 시작 인덱스는 0이 아닌 1부터 시작.</li>
<li>만약 for 조건의 i의 값을 1부터 설정하게 된다면 그것은 단지 전체 인덱스에서 인덱스[1]부터 순회한다는 뜻</li>
<li>그렇기에 if의 조건에 code를 나눈 나머지가 0이 되는 자리수를 분명하게 반환할 수 있음.</li>
</ol>
<hr>
<h3 id="😭-문제-핥짝-2">😭 문제 핥짝 #2</h3>
<blockquote>
<p><strong>[프로그래머스]</strong> Lv0 : 카운트 다운</p>
</blockquote>
<p><strong>문제 설명</strong> 
정수 start와 end가 주어질 때, start에서 end까지 1씩 감소하는 수들을 차례로 담은 리스트를 return하도록 solution 함수를 완성해주세요.</p>
<p><strong>제한사항</strong></p>
<ul>
<li>0 ≤ end ≤ start ≤ 50</li>
</ul>
<p><strong>입출력 예</strong></p>
<table>
<thead>
<tr>
<th align="center">start</th>
<th align="center">end</th>
<th align="center">result</th>
</tr>
</thead>
<tbody><tr>
<td align="center">10</td>
<td align="center">3</td>
<td align="center">[10,9,8,7,6,5,4,3]</td>
</tr>
</tbody></table>
<hr>
<h3 id="나의-풀이-1">나의 풀이</h3>
<pre><code class="language-js">function solution(start, end) {
  var answer = [];

  while (start != end - 1) {
    answer.push(start);
    start--;
  }
  return answer;
}
</code></pre>
<p><strong>상태 접근</strong></p>
<ol>
<li>while을 통해 해당 start값이 end -1가 될때까지 순회.</li>
</ol>
<hr>
<h3 id="다른사람-풀이">다른사람 풀이</h3>
<pre><code class="language-js">function solution(start, end) {
    return Array.from(Array(start - end + 1), (_, i) =&gt; start - i);
}</code></pre>
<p>풀이</p>
<ol>
<li>Array.from( ) 메소드를 유사배열 객체를 만들어 냄.</li>
</ol>
<p><a href="https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Array/from">MDN - Array.from()</a>
*<em>Array.from() *</em>메서드는 유사 배열 객체(array-like object)나 반복 가능한 객체(iterable object)를 얕게 복사해 새로운Array 객체를 만듭니다.</p>
<p>구문
<code>Array.from(arrayLike[, mapFn[, thisArg]])</code></p>
<p><code>arrayLike</code>
배열로 변환하고자 하는유사 배열 객체나 반복 가능한 객체.</p>
<p><code>mapFnOptional</code>
배열의 모든 요소에 대해 호출할 맵핑 함수.</p>
<p><code>thisArgOptional</code>
mapFn 실행 시에 this로 사용할 값.</p>
<pre><code class="language-js">function solution(start, end) {
  return Array.from({ length: start - end + 1 }, (_, i) =&gt; start - i);
}</code></pre>
<p>배열 객체를 만들기 위해 조건에 맞는 반복가능한 배열 작성할 수 있음.</p>
<hr>
<h3 id="😭-문제-핥짝-3">😭 문제 핥짝 #3</h3>
<blockquote>
<p><strong>[프로그래머스]</strong> Lv0 : 가위 바위 보</p>
</blockquote>
<p><strong>문제 설명</strong> 
가위는 2 바위는 0 보는 5로 표현합니다. 가위 바위 보를 내는 순서대로 나타낸 문자열 rsp가 매개변수로 주어질 때, rsp에 저장된 가위 바위 보를 모두 이기는 경우를 순서대로 나타낸 문자열을 return하도록 solution 함수를 완성해보세요.</p>
<p><strong>제한사항</strong></p>
<ul>
<li>0 &lt; rsp의 길이 ≤ 100</li>
<li>rsp와 길이가 같은 문자열을 return 합니다.</li>
<li>rsp는 숫자 0, 2, 5로 이루어져 있습니다.</li>
</ul>
<p><strong>입출력 예</strong></p>
<table>
<thead>
<tr>
<th align="center">end</th>
<th align="center">result</th>
</tr>
</thead>
<tbody><tr>
<td align="center">&quot;2&quot;</td>
<td align="center">&quot;0&quot;</td>
</tr>
<tr>
<td align="center">&quot;205&quot;</td>
<td align="center">&quot;052&quot;</td>
</tr>
</tbody></table>
<hr>
<h3 id="나의-풀이-2">나의 풀이</h3>
<pre><code class="language-js">function solution(rsp) {
  var answer = &quot;&quot;;
  if (rsp.includes(&quot;2&quot;)) answer = rsp.replaceAll(&quot;2&quot;, &quot;0&quot;);
  else if (rsp.includes(&quot;0&quot;)) answer = rsp.replaceAll(&quot;0&quot;, &quot;5&quot;);
  else if (rsp.includes(&quot;5&quot;)) answer = rsp.replaceAll(&quot;5&quot;, &quot;2&quot;);
  return answer;
}</code></pre>
<p><strong>상태 접근</strong></p>
<ol>
<li>else if를 통해 연속된 조건에 answer 값을 재할당 하면 값이 나올 줄 앎.</li>
<li>하지만 answer는 해당 조건이 모두 통과한 마지막 값만 수정해서 반환.</li>
</ol>
<p><strong>문제 접근</strong></p>
<ol>
<li>연속된 조건에 해당하는 반복을 처리하던가.</li>
</ol>
<pre><code class="language-js">function solution(rsp) {
  var answer = &quot;&quot;;
  let arr = rsp.split(&quot;&quot;);
  for (let i = 0; i &lt; arr.length; i++) {
    if (arr[i] === &quot;0&quot;) answer += &quot;5&quot;;
    if (arr[i] === &quot;2&quot;) answer += &quot;0&quot;;
    if (arr[i] === &quot;5&quot;) answer += &quot;2&quot;;
  }
  return answer;
}</code></pre>
<ol start="2">
<li>삼항연산자 사용이 있으며 <pre><code class="language-js">function solution(rsp) {
 return rsp.split(&quot;&quot;).map((v) =&gt; v===&quot;2&quot; ? 0 : (v===&quot;0&quot; ? 5 : 2)).join(&quot;&quot;)
}</code></pre>
</li>
</ol>
<p>3.객체를 통해 매핑한 다음 반복 해주는 방법이 있다.</p>
<pre><code class="language-js">function solution(rsp) {
const mapping = {
&quot;2&quot;: &quot;0&quot;,
&quot;0&quot;: &quot;5&quot;,
&quot;5&quot;: &quot;2&quot;
};
let answer = &quot;&quot;;
for (let i = 0; i &lt; rsp.length; i++) {
const char = rsp[i];
if (char in mapping) {
answer += mapping[char];
} else {
answer += char;
}
}
return answer;
}</code></pre>
<p>위 코드를 개선해보면</p>
<pre><code class="language-js">/*
 가위는 2 바위는 0 보는 5
*/
function solution(rsp) {
    let arr = {
        2: 0,
        0: 5,
        5: 2
    };
    var answer = [...rsp].map(v =&gt; arr[v]).join(&quot;&quot;);
    return answer;
}</code></pre>
<p>위와 같이 개선 가능함.</p>
<hr>
<h3 id="🤪-오늘의-학습">🤪 오늘의 학습</h3>
<p>객체를 통한 값을 매핑하는 방법과 객체 사용의 의의에 대해 다시금 생각할 수 있게 됨.</p>
]]></description>
        </item>
        <item>
            <title><![CDATA[🟣 오늘의 문제 회고]]></title>
            <link>https://velog.io/@woo_7i/%EC%98%A4%EB%8A%98%EC%9D%98-%EB%AC%B8%EC%A0%9C-%ED%9A%8C%EA%B3%A0-0xjk83r8</link>
            <guid>https://velog.io/@woo_7i/%EC%98%A4%EB%8A%98%EC%9D%98-%EB%AC%B8%EC%A0%9C-%ED%9A%8C%EA%B3%A0-0xjk83r8</guid>
            <pubDate>Sun, 16 Apr 2023 01:39:55 GMT</pubDate>
            <description><![CDATA[<h3 id="😭-오늘의-문제-핥짝-1">😭 오늘의 문제 핥짝 #1</h3>
<blockquote>
<p><strong>[프로그래머스]</strong> Lv0 : 개미 군단</p>
</blockquote>
<p><strong>문제 설명</strong> 
개미 군단이 사냥을 나가려고 합니다. 개미군단은 사냥감의 체력에 딱 맞는 병력을 데리고 나가려고 합니다. 장군개미는 5의 공격력을, 병정개미는 3의 공격력을 일개미는 1의 공격력을 가지고 있습니다. 예를 들어 체력 23의 여치를 사냥하려고 할 때, 일개미 23마리를 데리고 가도 되지만, 장군개미 네 마리와 병정개미 한 마리를 데리고 간다면 더 적은 병력으로 사냥할 수 있습니다. 사냥감의 체력 hp가 매개변수로 주어질 때, 사냥감의 체력에 딱 맞게 최소한의 병력을 구성하려면 몇 마리의 개미가 필요한지를 return하도록 solution 함수를 완성해주세요.</p>
<p><strong>제한사항</strong></p>
<ul>
<li>hp는 자연수입니다.</li>
<li>0 ≤ hp ≤ 1000</li>
</ul>
<p><strong>입출력 예</strong></p>
<table>
<thead>
<tr>
<th align="center">hp</th>
<th align="center">result</th>
</tr>
</thead>
<tbody><tr>
<td align="center">23</td>
<td align="center">5</td>
</tr>
<tr>
<td align="center">24</td>
<td align="center">6</td>
</tr>
<tr>
<td align="center">999</td>
<td align="center">201</td>
</tr>
</tbody></table>
<hr>
<h3 id="나의-풀이">나의 풀이</h3>
<pre><code class="language-js">
function solution(hp) {
  const first = Math.floor(hp / 5);

  const second = Math.floor((hp % 5) / 3);

  const third = (hp%5)%3;

  return first + second + third;
}</code></pre>
<p><strong>상태 접근</strong></p>
<ol>
<li>hp를 최소로 사용하기 위해 장군 개미를 가장 많이 투자해야 함.</li>
<li>장군개미를 나눈 나머지 값에 병정 개미를 투자.</li>
<li>두 상위 개미를 사용한 나머지 값에 일 개미 투자.</li>
</ol>
<hr>
<h3 id="😭-오늘의-문제-핥짝-2">😭 오늘의 문제 핥짝 #2</h3>
<blockquote>
<p><strong>[프로그래머스]</strong> Lv0 : 자릿수 더하기</p>
</blockquote>
<p><strong>문제 설명</strong> 
정수 n이 매개변수로 주어질 때 n의 각 자리 숫자의 합을 return하도록 solution 함수를 완성해주세요</p>
<p><strong>제한사항</strong></p>
<ul>
<li>0 ≤ n ≤ 1,000,000</li>
</ul>
<p><strong>입출력 예</strong></p>
<table>
<thead>
<tr>
<th align="center">hp</th>
<th align="center">result</th>
</tr>
</thead>
<tbody><tr>
<td align="center">1234</td>
<td align="center">10</td>
</tr>
<tr>
<td align="center">930211</td>
<td align="center">16</td>
</tr>
</tbody></table>
<hr>
<h3 id="나의-풀이-1">나의 풀이</h3>
<pre><code class="language-js">function solution(n) {
  var answer = n
    .toString(10)
    .split(&quot;&quot;)
    .reduce((a, c) =&gt; a + parseInt(c), 0);
  return answer;
}</code></pre>
<p><strong>상태 접근</strong>
1.연속된 숫자를 나누기 위해 배열로 반환하기 위해 문자열로 변환
2. split 메소를 이용하여 각각의 숫자를 개별로 나눈 배열로 반환
3. reduce 함수를 통해 형변환한 현재값을 더해 누산.</p>
<hr>
<h3 id="다른-풀이">다른 풀이</h3>
<pre><code class="language-js">function solution(n) {
  var answer = [];
  while (n &gt; 0) {
    answer.unshift(n % 10);
    n = Math.floor(n / 10);
  }
  return answer.reduce();
}</code></pre>
<p>풀이
예전 이와 비슷한 문제를 풀었을 때 문자열 형 변환을 하지 않고 자리 수를 구하는 풀이 구현을 한 것이 기억에 남아 다시금 사용해보았다.</p>
]]></description>
        </item>
        <item>
            <title><![CDATA[🟣 오늘의 문제 회고]]></title>
            <link>https://velog.io/@woo_7i/%EC%98%A4%EB%8A%98%EC%9D%98-%EB%AC%B8%EC%A0%9C-%ED%9A%8C%EA%B3%A0-3iqn5haw</link>
            <guid>https://velog.io/@woo_7i/%EC%98%A4%EB%8A%98%EC%9D%98-%EB%AC%B8%EC%A0%9C-%ED%9A%8C%EA%B3%A0-3iqn5haw</guid>
            <pubDate>Fri, 14 Apr 2023 15:34:09 GMT</pubDate>
            <description><![CDATA[<h3 id="😭-오늘의-문제-핥짝-1">😭 오늘의 문제 핥짝 #1</h3>
<blockquote>
<p><strong>[프로그래머스]</strong> Lv0 : 모음 제거</p>
</blockquote>
<p><strong>문제 설명</strong> 
영어에선 a, e, i, o, u 다섯 가지 알파벳을 모음으로 분류합니다. 문자열 my_string이 매개변수로 주어질 때 모음을 제거한 문자열을 return하도록 solution 함수를 완성해주세요.</p>
<p><strong>제한사항</strong></p>
<ul>
<li>my_string은 소문자와 공백으로 이루어져 있습니다.</li>
<li>1 ≤ my_string의 길이 ≤ 1,000</li>
</ul>
<p><strong>입출력 예</strong></p>
<table>
<thead>
<tr>
<th align="center">my_string</th>
<th align="center">result</th>
</tr>
</thead>
<tbody><tr>
<td align="center">&quot;bus&quot;</td>
<td align="center">&quot;bs&quot;</td>
</tr>
<tr>
<td align="center">&quot;nice to meet you&quot;</td>
<td align="center">&quot;nc t mt y&quot;</td>
</tr>
</tbody></table>
<hr>
<h3 id="나의-풀이">나의 풀이</h3>
<pre><code class="language-js">function solution(my_string) {
  let vowel = [&quot;a&quot;, &quot;e&quot;, &quot;i&quot;, &quot;o&quot;, &quot;u&quot;];
  var answer = my_string.split(&quot;&quot;).filter((e) =&gt; !vowel.includes(e));
  return answer.join(&quot;&quot;);
}</code></pre>
<p><strong>구현 접근</strong></p>
<ol>
<li>해당 모음이 존재하는지 판단하기 위한 메소드 사용이 필요할 거 같아 문자열 입력 값을 배열로 반환</li>
<li>filter를 통해 현재 값 e에 vowel값이 포함되어있는지,
NOT 논리연산자 (!)를 통해 모음이 포함되어 있지 않은 값을 반환하는 함수 구현</li>
<li>join 메소드를 통해서 반환된 문자열 배열을 문자열로 병합</li>
</ol>
<p><strong>문제점</strong></p>
<ol>
<li><p>문제를 풀 때 계속해서 참고만 하고 스스로 풀 노력을 하지 않아서 문제를 푸는 사고가 늘지 않는 것을 스스로 깨달음</p>
</li>
<li><p>다시 LV0 부터 코테까지 되는데로 문제를 풀도록 노력할 것.</p>
</li>
</ol>
<hr>
<h3 id="😭-오늘의-문제-핥짝-2">😭 오늘의 문제 핥짝 #2</h3>
<blockquote>
<p><strong>[프로그래머스]</strong> Lv0 : 배열의 유사도</p>
</blockquote>
<p><strong>문제 설명</strong> 
두 배열이 얼마나 유사한지 확인해보려고 합니다. 문자열 배열 s1과 s2가 주어질 때 같은 원소의 개수를 return하도록 solution 함수를 완성해주세요.</p>
<p><strong>제한사항</strong></p>
<ul>
<li>1 ≤ s1, s2의 길이 ≤ 100</li>
<li>1 ≤ s1, s2의 원소의 길이 ≤ 10</li>
<li>s1과 s2의 원소는 알파벳 소문자로만 이루어져 있습니다</li>
<li>s1과 s2는 각각 중복된 원소를 갖지 않습니다.</li>
</ul>
<p><strong>입출력 예</strong></p>
<table>
<thead>
<tr>
<th align="center">s1</th>
<th align="center">s2</th>
<th align="center">result</th>
</tr>
</thead>
<tbody><tr>
<td align="center">[&quot;a&quot;, &quot;b&quot;, &quot;c&quot;]</td>
<td align="center">[&quot;com&quot;, &quot;b&quot;, &quot;d&quot;, &quot;p&quot;, &quot;c&quot;]</td>
<td align="center">2</td>
</tr>
<tr>
<td align="center">[&quot;n&quot;, &quot;omg&quot;]</td>
<td align="center">[&quot;m&quot;, &quot;dot&quot;]</td>
<td align="center">0</td>
</tr>
</tbody></table>
<hr>
<h3 id="나의-풀이-1">나의 풀이</h3>
<pre><code class="language-js">function solution(s1, s2) {
  var answer = s1.filter((e) =&gt; s2.includes(e)).length;
  return answer;
}</code></pre>
<p><strong>구현 접근</strong></p>
<ol>
<li>해당 문제 역시 위 문제와 같은 형식의 구현이었기에 그대로 풀 수 있었다.</li>
</ol>
<hr>
<h3 id="😭-오늘의-문제-핥짝-3">😭 오늘의 문제 핥짝 #3</h3>
<blockquote>
<p><strong>[프로그래머스]</strong> Lv0 : 숨어있는 숫자의 덧셈 (1)</p>
</blockquote>
<p><strong>문제 설명</strong> 
문자열 my_string이 매개변수로 주어집니다. my_string안의 모든 자연수들의 합을 return하도록 solution 함수를 완성해주세요.</p>
<p><strong>제한사항</strong></p>
<ul>
<li>1 ≤ my_string의 길이 ≤ 1,000</li>
<li>my_string은 소문자, 대문자 그리고 한자리 자연수로만 구성되어있습니다.</li>
</ul>
<p><strong>입출력 예</strong></p>
<table>
<thead>
<tr>
<th align="center">my_string</th>
<th align="center">result</th>
</tr>
</thead>
<tbody><tr>
<td align="center">&quot;aAb1B2cC34oOp&quot;</td>
<td align="center">10</td>
</tr>
<tr>
<td align="center">&quot;1a2b3c4d123&quot;</td>
<td align="center">16</td>
</tr>
</tbody></table>
<hr>
<h3 id="나의-풀이-2">나의 풀이</h3>
<pre><code class="language-js">function solution(my_string) {
  var answer = my_string
    .split(&quot;&quot;)
    .filter((e) =&gt; !isNaN(e))
    .reduce((a, c) =&gt; a + parseInt(c), 0);
  return answer;
}</code></pre>
<p><strong>구현 접근</strong>
1.구별 없이 섞여있는 배열을 하나씩 나누기 위해 split 메소드 사용.
2. filter를 통해 문자열 엘리먼트 들을 각각 형변환 시 NaN이 되지 않는 값 반환.
3. reduce를 사용하여 현재(c) 값을 형변환 시켜준 뒤 초기 값을 0으로 설정하여 누산.</p>
]]></description>
        </item>
        <item>
            <title><![CDATA[🟣 오늘의 문제 회고]]></title>
            <link>https://velog.io/@woo_7i/%EC%98%A4%EB%8A%98%EC%9D%98-%EB%AC%B8%EC%A0%9C-%ED%9A%8C%EA%B3%A0-8o9k559o</link>
            <guid>https://velog.io/@woo_7i/%EC%98%A4%EB%8A%98%EC%9D%98-%EB%AC%B8%EC%A0%9C-%ED%9A%8C%EA%B3%A0-8o9k559o</guid>
            <pubDate>Thu, 13 Apr 2023 15:15:10 GMT</pubDate>
            <description><![CDATA[<h3 id="😘-오늘의-문제-핥짝-1">😘 오늘의 문제 핥짝 #1</h3>
<blockquote>
<p><strong>[프로그래머스]</strong> Lv1 : 3진법 뒤집기</p>
</blockquote>
<p><strong>문제 설명</strong> 
자연수 n이 매개변수로 주어집니다. n을 3진법 상에서 앞뒤로 뒤집은 후, 이를 다시 10진법으로 표현한 수를 return 하도록 solution 함수를 완성해주세요.</p>
<p><strong>제한사항</strong></p>
<ul>
<li>n은 1 이상 100,000,000 이하인 자연수입니다.</li>
</ul>
<p><strong>입출력 예</strong></p>
<table>
<thead>
<tr>
<th align="center">n</th>
<th align="center">result</th>
</tr>
</thead>
<tbody><tr>
<td align="center">45</td>
<td align="center">7</td>
</tr>
<tr>
<td align="center">125</td>
<td align="center">229</td>
</tr>
</tbody></table>
<hr>
<h3 id="나의-풀이">나의 풀이</h3>
<pre><code class="language-js">function solution(n) {
  var answer = n
    .toString(3)
    .split(&quot;&quot;)
    .reduce((acc, cur) =&gt; cur + acc, &quot;&quot;);
  return parseInt(answer, 3);
}</code></pre>
<p><strong>구현 접근</strong>
<a href="https://jae04099.tistory.com/entry/%EC%9E%90%EB%B0%94%EC%8A%A4%ED%81%AC%EB%A6%BD%ED%8A%B8-%EC%A7%84%EC%88%98%EB%B3%80%ED%99%98-toString-parseInt">정수 진수 변환</a></p>
<ol>
<li>정수 n을 toString을 통해 특정 진수를 문자열로 반환.</li>
<li>split(&quot;&quot;)를 통해 배열로 반환 후</li>
<li>reduce를 통해 문자열을 뒤집어서 반환. </li>
</ol>
<p>-이번에는 reverse를 사용하지 않고 뒤집는 방법이 무엇있을까 고민하다 사용하게 됨!
4. parseInt를 통해 10진수로 다시 변환.</p>
<p><strong>parseInt</strong> 문자열을 특정 진수의 정수로 변환한다.
인수로는 parseInt(&#39;변환시키고자하는 문자열&#39;, 해당 수의 진수) 가 들어간다.</p>
<hr>
<h3 id="다른-사람-풀이">다른 사람 풀이</h3>
<p>#1</p>
<pre><code class="language-js">const solution = (n) =&gt; {
    return parseInt([...n.toString(3)].reverse().join(&quot;&quot;), 3);
}</code></pre>
<p>풀이
스프레드 문법을 통해 3진수로 변화한 정수들을 배열로 반환한 한 줄 코드</p>
<p>#2</p>
<pre><code class="language-js">function solution(n) {
    return parseInt(n.toString(3).split(&#39;&#39;).reverse().join(&#39;&#39;), 3);
}</code></pre>
<p>풀이
return에 parseInt의 인자로 한번에 메서드를 적용하여 한 줄 코드 작성.</p>
<hr>
<h3 id="😘-오늘의-문제-핥짝-2">😘 오늘의 문제 핥짝 #2</h3>
<blockquote>
<p><strong>[프로그래머스]</strong> Lv1 : 이상한 문자 만들기</p>
</blockquote>
<p><strong>문제 설명</strong> 
문자열 s는 한 개 이상의 단어로 구성되어 있습니다. 각 단어는 하나 이상의 공백문자로 구분되어 있습니다. 각 단어의 짝수번째 알파벳은 대문자로, 홀수번째 알파벳은 소문자로 바꾼 문자열을 리턴하는 함수, solution을 완성하세요.</p>
<p><strong>제한사항</strong></p>
<ul>
<li>문자열 전체의 짝/홀수 인덱스가 아니라, 단어(공백을 기준)별로 짝/홀수 인덱스를 판단해야합니다.</li>
<li>첫 번째 글자는 0번째 인덱스로 보아 짝수번째 알파벳으로 처리해야 합니다.</li>
</ul>
<p><strong>입출력 예</strong></p>
<table>
<thead>
<tr>
<th align="center">s</th>
<th align="center">return</th>
</tr>
</thead>
<tbody><tr>
<td align="center">&quot;try hello world&quot;</td>
<td align="center">&quot;TrY HeLlO WoRlD&quot;</td>
</tr>
</tbody></table>
<hr>
<h3 id="나의-풀이-1">나의 풀이</h3>
<pre><code class="language-js">function solution(s) {
  let answer = s.split(&quot;&quot;);
  for (let i = 0; i &lt; answer.length; i++) {
    if (answer[i] === &quot;&quot;) return &quot;&quot;;
    if (i % 2 === 0 || i === 0) answer[i].toUpperCase();
    else answer[i].toLowerCase();
    console.log(answer);
  }
  return answer;</code></pre>
<p><strong>구현 접근</strong></p>
<ol>
<li>전체 문자열을 나뉘어 배열로 반환.</li>
<li>for문을 순회하며 i의 값이 짝수면 해당 인덱스 값을 대문자로 변환하여 할당.</li>
<li>홀수면 소문자로 변환하여 할당.</li>
</ol>
<p><strong>문제점</strong></p>
<ol>
<li>변환한 값을 할당을 해줘야 하는데 할당을 하지 않고 변환만 하여 return 되는 값이 없었다.</li>
</ol>
<pre><code class="language-js">for (let i = 0; i &lt; answer.length; i++) {
  if (i % 2 === 0) {
    answer[i] = answer[i].toUpperCase();
  } else {
    answer[i] = answer[i].toLowerCase();
  }
}
return answer.join(&quot; &quot;);
</code></pre>
<p>개선은 완료 했지만, 해당 코드의 문제점은 
전체 문자열을 순회하고 있기 때문에 공백을 기준으로 대 소문자를 나뉘지 못 함.</p>
<hr>
<p><strong>split 메소드에 공백을 추가하여 단어별로 나뉘었을 때 풀이.</strong></p>
<pre><code class="language-js">function solution(s) {
  if (s === &quot;&quot;) return &quot;&quot;;

  let answer = s.split(&quot; &quot;);
  for (let i = 0; i &lt; answer.length; i++) {
    for (let j = 0; j &lt; answer[i].length; j++) {
      if (j % 2 === 0) {
        answer[i] = answer[i].substr(0, j) + answer[i][j].toUpperCase() + answer[i].substr(j + 1);
      } else {
        answer[i] = answer[i].substr(0, j) + answer[i][j].toLowerCase() + answer[i].substr(j + 1);
      }
    }
  }
  return answer.join(&quot; &quot;);

}
</code></pre>
<p>이 코드에서는 
<code>answer[i].substr(0, j) + answer[i][j].toUpperCase() + answer[i].substr(j + 1)</code>
를 사용하여 answer[i]의 j번째 문자를 대문자 또는 소문자로 변경하고, 변경된 문자열을 answer[i]에 다시 할당합니다. 마지막으로, join() 함수를 사용하여 배열의 요소를 공백으로 연결하여 최종 결과를 반환합니다.</p>
<p><a href="https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/String/substring">MDN-String.substring( ) 메소드 개념</a>
String.prototype.substring()
substring() 메소드는 string 객체의 시작 인덱스로 부터 종료 인덱스 전 까지 문자열의 부분 문자열을 반환합니다.</p>
<p><code>구문 : 
str.substring(indexStart[, indexEnd])</code></p>
<p><code>indexStart</code>
반환문자열의 시작 인덱스</p>
<p><code>indexEnd</code>
옵션. 반환문자열의 마지막 인덱스 (포함하지 않음.)</p>
<p>split메소드에 공백을 추가하여 해당 배열들을 나뉘어 각각의 단어별로 배열을 나뉘었지만, 
이중 for문을 사용하고 싶지 않아 개선점을 물어보게 됐다. </p>
<hr>
<h3 id="챗gpt-풀이">챗gpt 풀이</h3>
<p>이중 for문을 없앨 수 있는 방법은 다양하지만, 
한 가지 방법은 split() 함수를 사용하지 않고 문자열을 순회하면서 단어와 각 단어의 짝/홀수 인덱스를 판단하는 것입니다. </p>
<p>이를 위해 먼저 단어의 시작과 끝 인덱스를 찾아야 합니다. 
단어의 시작 인덱스는 바로 이전 문자가 공백이거나 문자열의 시작일 때이고, 단어의 끝 인덱스는 다음 문자가 공백이거나 문자열의 끝일 때입니다.</p>
<pre><code class="language-js">function solution(s) {
  if (s === &quot;&quot;) return &quot;&quot;;

  let answer = &quot;&quot;;
  let isEven = true;

  for (let i = 0; i &lt; s.length; i++) {
    if (s[i] === &quot; &quot;) {
      //단어의 시작이 공백인 경우 공백 그대로 추가.
      answer += &quot; &quot;;

      // 문자가 아닌 경우 단어의 시작 또는 끝인지 확인.
      isEven = true; 
      continue;
    }

    if (isEven) { // 단어를 순회하며 짝수일 때 대문자로 변환 값 재할당
      answer += s[i].toUpperCase();
      isEven = false; // false로 만들어 다음 오는 인덱스를 홀수로 판단.
    } else {    // false의 else는 소문자로 변환 값 재할당.
      answer += s[i].toLowerCase();
      isEven = true; // 
    }
  }

  return answer;
}
</code></pre>
<p>이 코드에서는 isEven 변수를 사용하여 현재 문자가 짝수 인덱스인지 여부를 추적합니다. for 루프를 사용하여 문자열의 각 문자를 순회하면서, 현재 문자가 공백인 경우는 그대로 추가하고, 문자가 아닌 경우는 단어의 시작 또는 끝인지를 확인합니다.
이를 통해 각 문자를 짝/홀수 인덱스에 따라 대소문자로 변환하여 새 문자열 answer에 추가합니다. 마지막으로 answer를 반환합니다.</p>
<p> isEven 변수는 현재 문자의 인덱스가 짝수인지 여부를 추적하는 데 사용됩니다. 
 따라서 현재 문자가 단어의 시작이면, isEven 변수를 false로 설정하여 다음 문자가 홀수 인덱스가 되도록 합니다. 
 그렇게 함으로써 다음 문자를 소문자로 변환합니다.</p>
<p>반대로, 현재 문자가 단어의 끝이면, isEven 변수를 true로 설정하여 다음 문자가 짝수 인덱스가 되도록 합니다. 그렇게 함으로써 다음 문자를 대문자로 변환합니다.</p>
<p>따라서 isEven 변수를 false 또는 true로 재할당하는 것은 다음 문자를 대소문자로 변환하기 위한 작업입니다.</p>
]]></description>
        </item>
        <item>
            <title><![CDATA[[중간 점검] 목표를 향해서!]]></title>
            <link>https://velog.io/@woo_7i/%EC%A4%91%EA%B0%84-%EC%A0%90%EA%B2%80-%EB%AA%A9%ED%91%9C%EB%A5%BC-%ED%96%A5%ED%95%B4%EC%84%9C</link>
            <guid>https://velog.io/@woo_7i/%EC%A4%91%EA%B0%84-%EC%A0%90%EA%B2%80-%EB%AA%A9%ED%91%9C%EB%A5%BC-%ED%96%A5%ED%95%B4%EC%84%9C</guid>
            <pubDate>Mon, 10 Apr 2023 14:45:39 GMT</pubDate>
            <description><![CDATA[<h3 id="😤-프로그래머스-데브코스를-지원하고자">😤 프로그래머스 데브코스를 지원하고자!</h3>
<p>벌써 4월의 2주차가 시작됐다. 
개발공부를 본격적으로 시작하게 된 건 작년 10월부터 였던 것 같은데, 
이런 저런 여건이 힘들어 1월까지 돈을 벌고 2월부터 차츰 올해의 목표를 실현하기 위해 한 걸음씩 발을 디딜 준비를 했던 것 같다.</p>
<ul>
<li><a href="https://velog.io/@woo_7i/%EA%B7%B8%EB%8F%99%EC%95%88%EC%9D%98-%EB%B0%9C%EC%9E%90%EC%B7%A8%EC%97%90">그동안의 발자취를 다룬 벨로그 ㅋ-ㅋ</a></li>
<li><a href="https://velog.io/@woo_7i/%EA%B3%84%ED%9A%8D-%EB%B3%80%EA%B2%BD">계획도 변경 해보고 바빴구만!</a></li>
</ul>
<blockquote>
<p>4월 1주차. (04.02~. 04.08)</p>
</blockquote>
<ol>
<li>오전 [프로그래머스] 자바스크립트 강의.</li>
<li>오후 [노마드코더(코코아 코딩)] 강의 듣고 나만의 프로젝트 완성할 것.</li>
<li>저녁 [프로그래머스] 코딩 테스트를 위한 알고리즘 문제 학습 2문제 이상씩, 풀고 피드백 및 블로그 정리</li>
<li>저녁 자소서 조금씩 만져보기</li>
</ol>
<blockquote>
<p>4월 2주차. (04.09 ~. 04.15)</p>
</blockquote>
<ol>
<li>오전 [유데미] 자바스크립트 프로젝트 강의를 통해 js 익숙해지기</li>
<li>오후 [노마드 코더] js 프로젝트 강의 듣기.</li>
<li>저녁  [프로그래머스] 코딩 테스트를 위한 알고리즘 문제 학습 2문제 이상씩, 풀고 피드백 및 블로그 정리</li>
<li>저녁 자소서 조금씩 만져보기</li>
</ol>
<p>3월달의 목표치를 다 이루지 못 해 4월로 밀린 목표들이 조금씩 밀려 지금까지 오긴 했지만,</p>
<p>제법 도서관도 꾸준히 다니고 책상에 앉는 버릇을 들여보니 이제는 오래 앉아서 집중하는 시간이 늘어났다.</p>
<p>우선 개발을 하는 것에 재미가 들린 것 같다!
<img src = https://velog.velcdn.com/images/woo_7i/post/8c6aaa81-28b1-4075-b621-14b5f65d92d3/image.png width="90%"></p>
<p>어려운 용어들과 아직은 이해하지 못 할 작동 처리방식들에 개념들만을 앉아서 펼쳐 볼 때는 어려움이 많고 지루함의 연속이었는데 이런 프로젝트가 섞인 강의를 들으며 개발에 재미를 붙일 수 있는 환경을 만들어 낸 것 같다.</p>
<hr>
<p>프로그래머스 선행 학습을 통해 길라잡이가 되어준 강의들이었지만 여전히 어려움이 있을 수 밖에 없었다, 실질적으로 웹사이트를 구축하고 서버를 통신하며 배포를 구현해본 프로젝트를 경험이 없었기에 해당 강의 용어들이 어떻게 진행이되고 적용이 되는지 이해가 어려운 부분이 없을 수가 없었다..</p>
<p>다양한 프로젝트 경험을 해보고 싶어 인프런이나 찾아봐도 생각보다 요구하는 조건들이 어느정도는 갖춘 사람들을 원하는 분들이 많았고,, </p>
<p>꼭 이번 기회를 통해서 프로그래머스 데브코스에서 성장을 하고 싶은 욕구가 절실해진 것 같다.</p>
<table>
<thead>
<tr>
<th><img src="https://velog.velcdn.com/images/woo_7i/post/8649e540-5668-4f0b-9392-885e8456244f/image.png" alt=""></th>
<th><img src="https://velog.velcdn.com/images/woo_7i/post/23fbc6cf-691f-475c-9f1b-8b3aa2db5d40/image.png" alt=""></th>
</tr>
</thead>
</table>
<hr>
<h3 id="매일-매일-업로드-하지만-발전이-없어-보이는-코테-🥲🥲">매일 매일 업로드 하지만 발전이 없어 보이는,, 코테 🥲🥲</h3>
<p><img src="https://velog.velcdn.com/images/woo_7i/post/93e82856-45ef-4551-a6c0-d03075858f02/image.png" alt=""></p>
<p>어느 덧, 70문제를 풀었다고 하지만 왜인지 도돌이표를 찍고있는 듯 한,,, 후..</p>
<p>하지만 4월 29일 코딩테스트 까진 시간이 있으니 꼭 100문제 이상을 해결하고 코테를 치루도록 하겠다!</p>
<hr>
<h3 id="😃-일일이-올릴-순-없어">😃 일일이 올릴 순 없어</h3>
<p>메모하는 습관은 좋다고 하지만 다음 부터는 markup 문서로 작업하는 습관을 들여야겠다. 
파일 업로드 기능이 없는 벨로그에선 문서 형식 파일은 업로드가 되지 않는다니,,!</p>
<ul>
<li><a href="https://drive.google.com/drive/u/0/folders/12ZodjjXthiDRDiehOE4EQ0468iNeor5_">구글드라이브 공유파일</a></li>
</ul>
<p>구글 드라이브로 공유 파일을 적용시켜 링크를 첨부할 수 있었다.</p>
<p>물론 다 기억하기는 어렵지만 드문 드문 기억나는 것들은 내가 메모한 문서를 찾아 복습을 할 수 있는 학습지 같은 셈인 것 같다.</p>
<p>아직은 목표까지 2주정도 시간이 남았으니 최대한 몰입하고 문제 해결 능력을 향상 시키는 것을 목표로 해야겠다.</p>
<p>남은 2주도 파이팅 해보자!</p>
]]></description>
        </item>
        <item>
            <title><![CDATA[🟣 오늘의 문제 회고]]></title>
            <link>https://velog.io/@woo_7i/%EC%98%A4%EB%8A%98%EC%9D%98-%EB%AC%B8%EC%A0%9C-%ED%9A%8C%EA%B3%A0-w1ueogvl</link>
            <guid>https://velog.io/@woo_7i/%EC%98%A4%EB%8A%98%EC%9D%98-%EB%AC%B8%EC%A0%9C-%ED%9A%8C%EA%B3%A0-w1ueogvl</guid>
            <pubDate>Mon, 10 Apr 2023 13:56:45 GMT</pubDate>
            <description><![CDATA[<h3 id="🥹-오늘의-문제-핥짝-1">🥹 오늘의 문제 핥짝 #1</h3>
<p><strong>문제 설명</strong> 
0과 1로 이루어진 어떤 문자열 x에 대한 이진 변환을 다음과 같이 정의합니다.</p>
<p>x의 모든 0을 제거합니다.
x의 길이를 c라고 하면, x를 &quot;c를 2진법으로 표현한 문자열&quot;로 바꿉니다.
예를 들어, x = &quot;0111010&quot;이라면, x에 이진 변환을 가하면 x = &quot;0111010&quot; -&gt; &quot;1111&quot; -&gt; &quot;100&quot; 이 됩니다.</p>
<p>0과 1로 이루어진 문자열 s가 매개변수로 주어집니다. s가 &quot;1&quot;이 될 때까지 계속해서 s에 이진 변환을 가했을 때, 이진 변환의 횟수와 변환 과정에서 제거된 모든 0의 개수를 각각 배열에 담아 return 하도록 solution 함수를 완성해주세요.</p>
<p><strong>제한사항</strong></p>
<ul>
<li>s의 길이는 1 이상 150,000 이하입니다.</li>
<li>s에는 &#39;1&#39;이 최소 하나 이상 포함되어 있습니다.</li>
</ul>
<p><strong>입출력 예</strong></p>
<table>
<thead>
<tr>
<th align="center">s</th>
<th align="center">result</th>
</tr>
</thead>
<tbody><tr>
<td align="center">&quot;110010101001&quot;</td>
<td align="center">[3,8]</td>
</tr>
<tr>
<td align="center">&quot;01110&quot;</td>
<td align="center">[3,3]</td>
</tr>
<tr>
<td align="center">&quot;1111111&quot;</td>
<td align="center">[4,1]</td>
</tr>
</tbody></table>
<hr>
<h3 id="나의-풀이">나의 풀이</h3>
<pre><code class="language-js">
function solution(x) {
  let answer = [0, 0];
  for (let count = 0; count &lt; x.length; count++) {
    let sliceZero = 0;
    x.split(&quot;&quot;).filter((e) =&gt; (e != &quot;0&quot; ? e : (sliceZero += e.length))).length;
    let inNum = toString(x.length);
  }
  if (inNum === 1) answer[0] = count;
}</code></pre>
<p><strong>구현 접근</strong></p>
<ol>
<li>answer에 [0,0] 배열을 할당하여 answer[0]에다 변환 된 누적 값을
answer[1]에다 제거된 0의 개수를 할당하려 했다.</li>
<li>for문을 적용한 것 부터가 문제의 시작이었다,,</li>
<li>반복을 통해 split메소드로 반환 된 배열을 filter 메소드를 통해 추출하려 했으나</li>
<li>여기서부터 생각이 이어나가지 못 했다.</li>
</ol>
<p>결국엔 GPT에게 코드리뷰를 하게 됐으며, 아주 냉혹한 피드백을 받을 수 있었다.
<img src = https://velog.velcdn.com/images/woo_7i/post/916cb1aa-7847-4bd3-80b6-bc8a14b1525b/image.png width="80%">
<img src =https://velog.velcdn.com/images/woo_7i/post/00ff1ad5-5c85-4584-a54c-31bb5c05ed98/image.png width ="80%"></p>
<p>그렇게 수정된 코드는</p>
<pre><code class="language-js">function solution(s) {
  let binaryCount = 0; // 이진 변환 횟수
  let zeroCount = 0; // 제거된 0의 개수

  while (s !== &quot;1&quot;) {
    // 1단계: 0 제거 및 제거된 0의 개수 누적
    zeroCount += s.split(&quot;0&quot;).length - 1;

    // 2단계: s를 이진수로 변환하여 새로운 s로 갱신
    s = (s.split(&quot;1&quot;).length - 1).toString(2);

    // 이진 변환 횟수 증가
    binaryCount++;
  }

  return [binaryCount, zeroCount];
}
</code></pre>
<p>해당 구현을 테스트한 결과 바로 테스트 통과를 할 수 있었다.</p>
<hr>
<h3 id="다른-사람-풀이">다른 사람 풀이</h3>
<p>#1</p>
<pre><code class="language-js">function solution(s) {
    var answer = [0,0];
    while(s.length &gt; 1) {
        answer[0]++;
        answer[1] += (s.match(/0/g)||[]).length;
        s = s.replace(/0/g, &#39;&#39;).length.toString(2);
    }
    return answer;
}</code></pre>
<p>풀이</p>
<ol>
<li>정규식을 이용한 메소드들을 이용하여 해당 함수를 구현 하였다.</li>
</ol>
<p>#2</p>
<pre><code class="language-js">function solution(s) {

    let answer = [0,0]

    while(s !== &#39;1&#39;) {
        s = s.split(&#39;&#39;);
        let temp = s.filter(v =&gt; v === &#39;1&#39;).length;
        answer[0] ++;
        answer[1] += s.length - temp;
        s = temp.toString(2);
    }

    return answer;
}</code></pre>
<p>풀이
1.인터넷에 검색을 통해 찾아본 결과 내가 하고자 했던 풀이 방식이 있었다.</p>
<hr>
<h3 id="🫠-소감">🫠 소감</h3>
<p>변수를 선언하는 것 부터 해서 해당 메소드를 이용하여 반환하는 값이 왜 필요한지, 
반환한 값을 어디에 어떻게 적용하고자 하는지, 
분명한 목적과 명확한 결과 대입이 있어야 한다는 것을 깨달을 수 있었다.</p>
<p>코드를 한 줄 한 줄 작성하면서 왜에 대한 생각을 꾸준히 대입할 수 있도록 노력 해야겠다.</p>
]]></description>
        </item>
        <item>
            <title><![CDATA[🟣 오늘의 문제 회고]]></title>
            <link>https://velog.io/@woo_7i/%EC%98%A4%EB%8A%98%EC%9D%98-%EB%AC%B8%EC%A0%9C-%ED%9A%8C%EA%B3%A0-3utr6zbp</link>
            <guid>https://velog.io/@woo_7i/%EC%98%A4%EB%8A%98%EC%9D%98-%EB%AC%B8%EC%A0%9C-%ED%9A%8C%EA%B3%A0-3utr6zbp</guid>
            <pubDate>Sat, 08 Apr 2023 17:04:37 GMT</pubDate>
            <description><![CDATA[<h3 id="🤭-오늘의-문제-핥짝-1">🤭 오늘의 문제 핥짝 #1</h3>
<blockquote>
<p><strong>[프로그래머스]</strong> Lv1: 같은 숫자는 싫어</p>
</blockquote>
<p><strong>문제 설명</strong> 
배열 arr가 주어집니다. 배열 arr의 각 원소는 숫자 0부터 9까지로 이루어져 있습니다. 이때, 배열 arr에서 연속적으로 나타나는 숫자는 하나만 남기고 전부 제거하려고 합니다. 단, 제거된 후 남은 수들을 반환할 때는 배열 arr의 원소들의 순서를 유지해야 합니다. 예를 들면,</p>
<ul>
<li>arr = [1, 1, 3, 3, 0, 1, 1] 이면 [1, 3, 0, 1] 을 return 합니다.</li>
<li>arr = [4, 4, 4, 3, 3] 이면 [4, 3] 을 return 합니다.
배열 arr에서 연속적으로 나타나는 숫자는 제거하고 남은 수들을 return 하는 solution 함수를 완성해 주세요.</li>
</ul>
<p><strong>제한사항</strong></p>
<ul>
<li>배열 arr의 크기 : 1,000,000 이하의 자연수</li>
<li>배열 arr의 원소의 크기 : 0보다 크거나 같고 9보다 작거나 같은 정수</li>
</ul>
<p><strong>입출력 예</strong></p>
<table>
<thead>
<tr>
<th align="center">arr</th>
<th align="center">answer</th>
</tr>
</thead>
<tbody><tr>
<td align="center">[1,1,3,3,0,1,1]</td>
<td align="center">[1,3,0,1]</td>
</tr>
<tr>
<td align="center">[4,4,3,3]</td>
<td align="center">[4,3]</td>
</tr>
</tbody></table>
<hr>
<h3 id="나의-풀이">나의 풀이</h3>
<pre><code class="language-js">
function solution(arr) {
  var answer = [];
  for (let i = 0; i &lt; arr.length; i++) {
    let firstId = arr[i];
    let secondId = arr[i + 1];
    if (firstId != secondId) answer.push(firstId);
  }
  return answer;
}</code></pre>
<p><strong>구현 접근</strong></p>
<ol>
<li>스택 문제였기에 반복문을 사용</li>
<li>anwer에 반복되어 추출된 엘리먼트를 할당하기 위해 빈 배열 만듬</li>
<li>for반복을 통해 0번째 인덱스와 1번째 인덱스 비교하는 포인터 만듬</li>
<li>조건을 통해 두 값이 같지 않으면 answer에 push</li>
</ol>
<p>풀이
이 전에 강의를 들으면서 몇 번 경험 해봤던 것 같아 기억을 다듬어 두 인덱스를 비교하는 코드를 구성해보았다.</p>
<hr>
<h3 id="다른사람-풀이">다른사람 풀이</h3>
<pre><code class="language-js">function solution(arr)
{
    return arr.filter((val,index) =&gt; val != arr[index+1]);
}</code></pre>
<p>풀이</p>
<ol>
<li>filter 메소드를 이용하여 return으로 반환 해야하는 조건에 두 인덱스를 비교하는 문을 구성.</li>
<li>깔끔하고 하나의 함수를 이용하여 한 번에 해결 가능,,</li>
</ol>
<hr>
<h3 id="🫠-소감">🫠 소감</h3>
<p>조금씩이라도 꾸준하게 그리고 함수를 구성하는 풀이를 끝까지 생각하고 해결 하도록 노력하자!</p>
]]></description>
        </item>
        <item>
            <title><![CDATA[🟣 오늘의 문제 회고]]></title>
            <link>https://velog.io/@woo_7i/%EC%98%A4%EB%8A%98%EC%9D%98-%EB%AC%B8%EC%A0%9C-%ED%9A%8C%EA%B3%A0-tntn0nsg</link>
            <guid>https://velog.io/@woo_7i/%EC%98%A4%EB%8A%98%EC%9D%98-%EB%AC%B8%EC%A0%9C-%ED%9A%8C%EA%B3%A0-tntn0nsg</guid>
            <pubDate>Fri, 07 Apr 2023 13:29:07 GMT</pubDate>
            <description><![CDATA[<h3 id="🤫-오늘의-문제-핥짝-1">🤫 오늘의 문제 핥짝 #1</h3>
<blockquote>
<p><strong>[프로그래머스]</strong> Lv2: 최솟값 만들기</p>
</blockquote>
<p><strong>문제 설명</strong> 
길이가 같은 배열 A, B 두개가 있습니다. 각 배열은 자연수로 이루어져 있습니다.
배열 A, B에서 각각 한 개의 숫자를 뽑아 두 수를 곱합니다. 이러한 과정을 배열의 길이만큼 반복하며, 두 수를 곱한 값을 누적하여 더합니다. 이때 최종적으로 누적된 값이 최소가 되도록 만드는 것이 목표입니다. (단, 각 배열에서 k번째 숫자를 뽑았다면 다음에 k번째 숫자는 다시 뽑을 수 없습니다.)
예를 들어 A = [1, 4, 2] , B = [5, 4, 4] 라면</p>
<p>A에서 첫번째 숫자인 1, B에서 첫번째 숫자인 5를 뽑아 곱하여 더합니다. (누적된 값 : 0 + 5(1x5) = 5)
A에서 두번째 숫자인 4, B에서 세번째 숫자인 4를 뽑아 곱하여 더합니다. (누적된 값 : 5 + 16(4x4) = 21)
A에서 세번째 숫자인 2, B에서 두번째 숫자인 4를 뽑아 곱하여 더합니다. (누적된 값 : 21 + 8(2x4) = 29)
즉, 이 경우가 최소가 되므로 29를 return 합니다.</p>
<p>배열 A, B가 주어질 때 최종적으로 누적된 최솟값을 return 하는 solution 함수를 완성해 주세요.</p>
<p><strong>제한사항</strong></p>
<ul>
<li>배열 A, B의 크기 : 1,000 이하의 자연수</li>
<li>배열 A, B의 원소의 크기 : 1,000 이하의 자연수</li>
</ul>
<p><strong>입출력 예</strong></p>
<table>
<thead>
<tr>
<th align="center">a</th>
<th align="center">b</th>
<th align="center">answer</th>
</tr>
</thead>
<tbody><tr>
<td align="center">[1, 4, 2]</td>
<td align="center">[5, 4, 4]</td>
<td align="center">29</td>
</tr>
<tr>
<td align="center">[1,2]</td>
<td align="center">[3,4]</td>
<td align="center">10</td>
</tr>
</tbody></table>
<hr>
<h3 id="나의-풀이">나의 풀이</h3>
<pre><code class="language-js">function solution(a, b) {
  a.sort((a, b) =&gt; a - b);
  b.sort((a, b) =&gt; b - a);

  return a.reduce((a, c, i) =&gt; a + c * b[i], 0);
}</code></pre>
<p><strong>구현 접근</strong></p>
<ol>
<li>두 배열에 누적된 최솟값을 구하기 위해선 가장 작은 값 * 가장 큰 값 순으로 나열하여 누적하면 된다.</li>
<li>그러기 위해선 sort를 이용하여 각 배열을 오르, 내림 차순으로 정렬</li>
<li>reducde를 통해 인자를 받아와 현재의 작은 값과 b배열의 가장 큰값을 곱해서 누산 해가는 방식.</li>
</ol>
<p><strong>문제점</strong></p>
<ol>
<li>두 배열을 각각 곱하여 누적된 값이 최솟값이 되려면 가장 작은 값 * 가장 큰 값을 하여 더해줘야 한다는 사실.</li>
<li>map을 통하여 문제를 구현해보려 했는데 실패한 사실..</li>
<li>뭔가 생각을 더 많이 안 하는 것 같은,,</li>
</ol>
<p>좀 더 각성해서 문제를 조금이라도 스스로 풀려 노력해보자.</p>
<hr>
<h3 id="다른-사람-풀이">다른 사람 풀이</h3>
<p>#1</p>
<pre><code class="language-js">function getMinSum(A,B){
    var answer = 0;
  for (var i=0, ii = A.length; i&lt;ii ;i++){
     var max = Math.max(...A);
     var min = Math.min(...B);
     answer += max * min;
     A.splice(A.indexOf(max),1);
     B.splice(B.indexOf(min),1);
  }
    return answer;
}</code></pre>
<p>풀이</p>
<ol>
<li>for 문을 돌아 A 배열에서 가장 큰 값 추출</li>
<li>B 배열에서 가장 작은 값 추출</li>
<li>answer에 max * min 을 곱한 값을 누산</li>
<li>splice 메소드를 통해 추출된 값이 있는 배열 제거후 반환.</li>
</ol>
<p><a href="https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Array/splice">MDN - Array.splice 메소드</a></p>
<blockquote>
<p>*<em>splice() *</em>메서드는 배열의 기존 요소를 삭제 또는 교체하거나 새 요소를 추가하여 배열의 내용을 변경합니다.</p>
</blockquote>
<pre><code class="language-js">const months = [&#39;Jan&#39;, &#39;March&#39;, &#39;April&#39;, &#39;June&#39;];
months.splice(1, 0, &#39;Feb&#39;);
// Inserts at index 1
console.log(months);
// Expected output: Array [&quot;Jan&quot;, &quot;Feb&quot;, &quot;March&quot;, &quot;April&quot;, &quot;June&quot;]
months.splice(4, 1, &#39;May&#39;);
// Replaces 1 element at index 4
console.log(months);
// Expected output: Array [&quot;Jan&quot;, &quot;Feb&quot;, &quot;March&quot;, &quot;April&quot;, &quot;May&quot;]</code></pre>
<p><strong>구문</strong>
<code>array.splice(start[, deleteCount[, item1[, item2[, ...]]]])</code></p>
<p>더 정확한 설명은 해당 링크를 통해 살펴보자!</p>
]]></description>
        </item>
        <item>
            <title><![CDATA[🟣 오늘의 문제 회고]]></title>
            <link>https://velog.io/@woo_7i/%EC%98%A4%EB%8A%98%EC%9D%98-%EB%AC%B8%EC%A0%9C-%ED%9A%8C%EA%B3%A0-g9b76g6z</link>
            <guid>https://velog.io/@woo_7i/%EC%98%A4%EB%8A%98%EC%9D%98-%EB%AC%B8%EC%A0%9C-%ED%9A%8C%EA%B3%A0-g9b76g6z</guid>
            <pubDate>Tue, 04 Apr 2023 11:39:49 GMT</pubDate>
            <description><![CDATA[<h3 id="🤠-오늘의-문제-핥짝-1">🤠 오늘의 문제 핥짝 #1</h3>
<blockquote>
<p><strong>[프로그래머스]</strong> Lv2: 올바른 괄호</p>
</blockquote>
<p><strong>문제 설명</strong> 
괄호가 바르게 짝지어졌다는 것은 &#39;(&#39; 문자로 열렸으면 반드시 짝지어서 &#39;)&#39; 문자로 닫혀야 한다는 뜻입니다. 예를 들어</p>
<p>&quot;()()&quot; 또는 &quot;(())()&quot; 는 올바른 괄호입니다.
&quot;)()(&quot; 또는 &quot;(()(&quot; 는 올바르지 않은 괄호입니다.
&#39;(&#39; 또는 &#39;)&#39; 로만 이루어진 문자열 s가 주어졌을 때, 문자열 s가 올바른 괄호이면 true를 return 하고, 올바르지 않은 괄호이면 false를 return 하는 solution 함수를 완성해 주세요.</p>
<p><strong>제한사항</strong></p>
<ul>
<li>문자열 s의 길이 : 100,000 이하의 자연수</li>
<li>문자열 s는 &#39;(&#39; 또는 &#39;)&#39; 로만 이루어져 있습니다.</li>
</ul>
<p><strong>입출력 예</strong></p>
<table>
<thead>
<tr>
<th align="center">s</th>
<th align="center">answer</th>
</tr>
</thead>
<tbody><tr>
<td align="center">&quot;()()&quot;</td>
<td align="center">true</td>
</tr>
<tr>
<td align="center">&quot;(())()&quot;</td>
<td align="center">true</td>
</tr>
<tr>
<td align="center">&quot;)()(&quot;</td>
<td align="center">false</td>
</tr>
<tr>
<td align="center">&quot;(()(&quot;</td>
<td align="center">false</td>
</tr>
</tbody></table>
<hr>
<h3 id="나의-풀이">나의 풀이</h3>
<pre><code class="language-js">function solution(s) {
  var answer = s
    .split(&quot; &quot;)
    .every((e) =&gt;
      e[0] != &quot;(&quot; ? false : e[e.length - 1] != &quot;)&quot; ? false : true
    );

  return answer;
}</code></pre>
<p><strong>구현 접근</strong></p>
<ol>
<li>split 메소드를 이용하여 문자열 전체를 배열로 반환</li>
<li>every 메소드를 통해 e[0]~ e[마지막 인덱스] 를 순환하며 입력 값이 조건에 맞는지 blooean 값으로 반환.</li>
</ol>
<p><strong>문제점</strong>
구현까지는 완료가 됐는데 테스트 케이스 5, 11, 17 / 효율성 테스트 2번에서 통과를 하지 못 함.
<img src = https://velog.velcdn.com/images/woo_7i/post/8012e596-b800-4978-a5e6-9a430873781b/image.png width="80%"></p>
<p>이 질문의 댓글처럼 맨 앞과 뒤가 괄호가 정확하게 닫혀도, 중간에 이상이 생기면 구분하지 못 하는 함수가 됨.</p>
<p>더군다나 스택과 관련된 문제이니 코드의 효율성도 고려를 했어야 했던 부분인 것 같다.
<br>
<strong>개선</strong></p>
<pre><code class="language-js">function solution(s) {
  let answer = 0;

  for (let i = 0; i &lt; s.length; i++) {
    if (s[i] === &quot;(&quot;) answer += 1;
    else answer -= 1;
    if (answer &lt; 0) answer = false;
    console.log(answer);
  }
  return answer === 0;
}</code></pre>
<p>첫 번째 방향</p>
<ol>
<li>for문을 통해 s[i]의 값들 순회하여 &quot;(&quot; 조건과 맞는지 비교</li>
<li>비교를 통해 answer 값을 증감</li>
<li>증감 된 마지막 값이 0이 된다면 true를 반환.</li>
</ol>
<p><strong>문제점</strong></p>
<ol>
<li>for문을 순회하는 마지막 if 조건에서 answer에 false를 할당 해버려서 문제가 된 것.</li>
<li>그렇게되면 진행되는 도중 answer 값이 한번 false로 선언 됐다가 다시 for문은 순회하게 됨.
즉, false를 반환하는 것이 아닌 값으로 할당되어 계속 순회하게 되는 것.<img src = https://velog.velcdn.com/images/woo_7i/post/be2122ff-1144-4eec-929a-ea3cb7936e78/image.png width ="90%">

</li>
</ol>
<p><strong>해결 방법</strong></p>
<ol>
<li><p>answer에 값을 할당하는 것이 아닌 반복을 빠져나와 값을 반환하는 것.</p>
<pre><code class="language-js">function solution(s) {
let answer = 0;

for (let i = 0; i &lt; s.length; i++) {
 if (s[i] === &quot;(&quot;) answer += 1;
 else answer -= 1;
 if (answer &lt; 0) return false; // 올바르지 않은 괄호 문자열인 경우 false 반환하여 반복 종료.
}

return answer === 0; // 전체 문자열 검사 후 answer 값이 0이면 true, 아니면 false 반환
}</code></pre>
</li>
<li><p>continue 지시자를 통해 조건이 안 맞는 반복은 빠져나와 다음 조건으로 넘어가는 방식.</p>
<pre><code class="language-js">function solution(s){
 let open = 0;
 for(let i=0; i&lt;s.length; i++) {
     if(s[i] === &#39;(&#39;) {
         open++;
         continue;
     }
     if(!open) return false;
     open--;
 }
 return open ? false : true;
}</code></pre>
</li>
</ol>
<p>이번 기회를 통해 continue 지시자를 처음 알게 됐는데,,
<a href="https://ko.javascript.info/while-for">반복문 빠져나오기</a></p>
<h3 id="다음-반복으로-넘어가기">다음 반복으로 넘어가기</h3>
<blockquote>
<p>continue 지시자는 break의 &#39;가벼운 버전’입니다. 
continue는 전체 반복문을 멈추지 않습니다. 
대신에 현재 실행 중인 이터레이션을 멈추고 반복문이 다음 이터레이션을 강제로 실행시키도록 합니다(조건을 통과할 때). <br>
continue는 현재 반복을 종료시키고 다음 반복으로 넘어가고 싶을 때 사용할 수 있습니다.</p>
</blockquote>
<p>아래 반복문은 continue를 사용해 홀수만 출력합니다.</p>
<pre><code class="language-js">for (let i = 0; i &lt; 10; i++) {

  // 조건이 참이라면 남아있는 본문은 실행되지 않습니다.
  if (i % 2 == 0) continue;

  alert(i); // 1, 3, 5, 7, 9가 차례대로 출력됨
}</code></pre>
<p>i가 짝수이면 continue가 본문 실행을 중단시키고 다음 이터레이션이 실행되게 합니다(i가 하나 증가하고, 다음 반복이 실행됨). 
따라서 alert 함수는 인수가 홀수일 때만 호출됩니다.</p>
<hr>
<h3 id="다른-사람-풀이">다른 사람 풀이</h3>
<p>#1</p>
<pre><code class="language-js">function solution(s){
    let cum = 0
    for (let paren of s) {
        cum += paren === &#39;(&#39;? 1: -1
        if(cum &lt; 0) {
            return false
        }
    }
    return cum === 0? true: false;
}</code></pre>
<ol>
<li>for of 문과 삼항 연산자를 통해 식을 좀 더 추릴 수 있던 것 같다.</li>
</ol>
<hr>
<h3 id="😶-정리">😶 정리</h3>
<ol>
<li>스택 자료구조를 위한 코드를 구현하는 방법</li>
<li>반복 조건 continue 지시자를 통한 조건 넘기기</li>
</ol>
]]></description>
        </item>
        <item>
            <title><![CDATA[🟣 오늘의 문제 회고]]></title>
            <link>https://velog.io/@woo_7i/%EC%98%A4%EB%8A%98%EC%9D%98-%EB%AC%B8%EC%A0%9C-%ED%9A%8C%EA%B3%A0-psw5a9wm</link>
            <guid>https://velog.io/@woo_7i/%EC%98%A4%EB%8A%98%EC%9D%98-%EB%AC%B8%EC%A0%9C-%ED%9A%8C%EA%B3%A0-psw5a9wm</guid>
            <pubDate>Mon, 03 Apr 2023 11:28:12 GMT</pubDate>
            <description><![CDATA[<h3 id="🤦-오늘의-문제-핥짝-1">🤦 오늘의 문제 핥짝 #1</h3>
<blockquote>
<p><strong>[프로그래머스]</strong> Lv1: 직사각형 별찍기</p>
</blockquote>
<p><strong>문제 설명</strong> 
이 문제에는 표준 입력으로 두 개의 정수 n과 m이 주어집니다.
별(*) 문자를 이용해 가로의 길이가 n, 세로의 길이가 m인 직사각형 형태를 출력해보세요.</p>
<p><strong>제한사항</strong>
*n과 m은 각각 1000 이하인 자연수입니다.</p>
<p><strong>입출력 예</strong></p>
<table>
<thead>
<tr>
<th align="center">입력</th>
</tr>
</thead>
<tbody><tr>
<td align="center">5 3</td>
</tr>
</tbody></table>
<table>
<thead>
<tr>
<th align="center">출력</th>
</tr>
</thead>
<tbody><tr>
<td align="center">#####</td>
</tr>
<tr>
<td align="center">#####</td>
</tr>
<tr>
<td align="center">#####</td>
</tr>
</tbody></table>
<hr>
<h3 id="나의-풀이">나의 풀이</h3>
<pre><code class="language-js">function star(a, b) {
  let stars = &quot;&quot;;
  for (let i = 0; i &lt; b; i++) {
    for (let j = 0; j &lt; a; j++) {
      stars += &quot;*&quot;;
    }
    stars += &quot;\n&quot;;
  }
  return stars;
}</code></pre>
<p><strong>구현 접근</strong></p>
<ol>
<li>표준 입력 방식에 대해서도 다뤄보지 않았던 터라 입력이 어떻게 이뤄지고 입력 된 값이 왜 저렇게 반환 되는지 알 수 없었어서 결국 풀이를 참고,,<br></li>
<li>이중 for문을 적용시켜야 하는데 이중 for문의 원리 파악과 자바스크립트 동작 원리의 이해가 아직 부족했어서 결국 풀이를 참고 하였다,, ㅠㅠ</li>
</ol>
<p><strong>문제 점</strong></p>
<ol>
<li>표준 입력 방식에 대해 살펴보자.<img src= https://velog.velcdn.com/images/woo_7i/post/0a24ff48-9849-4ade-bc4f-47c339af0ddc/image.png wiith ="70%">
지금의 원리를 좀 더 이해하기 위해 프로그래머스 풀이 코드를 먼저 실행 해보았다.
<img src = https://velog.velcdn.com/images/woo_7i/post/ae54bd68-f3d9-4e89-b7ef-f5e11049ff30/image.png width ="70%">
실행 결과가 숫자 값 5와 3이 나오는 것을 확인하였다.
개발자 콘솔에서 받아온 입력값을 'data'인자에 입력하여 해당 
'data'를 배열에 맞게 형 변환을 해주는 함수인 셈이었다.

</li>
</ol>
<p><br>2. 이중 for문이 동작되는 원리와 자바스크립트가 코드를 읽어가는 원리에 대해 다시 한 번 생각하게 됐다.
<img src = https://velog.velcdn.com/images/woo_7i/post/e9253177-254e-4967-a395-df7141a77612/image.png width = "80%"></p>
<pre><code class="language-js">function star(a, b) {
  let stars = &quot;&quot;;
  for (let i = 0; i &lt; b; i++) {
    for (let j = 0; j &lt; a; j++) {
      stars += &quot;*&quot;;
    }
    stars += &quot;\n&quot;;
  }
  return stars;
}</code></pre>
<p>위 코드를 보면 for문의 원리는
즉, 첫 번째 for 블록 안의 for문이 다 실행 된 다음 블록 안의 두번 째 라인으로 넘어가 stars += &#39;\n&#39;이 실행되고 다시 for 조건으로 넘어온 다음 블록 안의 첫 번째 라인으로 향하게 되는 것.</p>
<p>다시 한 번 클로져(closure)의 원리와 자바스크립트 특성인 인터프리터어의 이해원리를 생각하게 되는 계기가 되었다.</p>
<hr>
<h3 id="다른-사람-풀이">다른 사람 풀이</h3>
<p>#1</p>
<pre><code class="language-js">process.stdin.setEncoding(&#39;utf8&#39;);
process.stdin.on(&#39;data&#39;, data =&gt; {
    const n = data.split(&quot; &quot;);
    const a = Number(n[0]), b = Number(n[1]);
    const row = &#39;*&#39;.repeat(a)
    for(let i =0; i &lt; b; i++){
        console.log(row)
    }

});</code></pre>
<p>풀이
반복에 반복을 쓸 필요 없이 repeat 메소드를 이용하여 repeat만큼 별이 반복되는 출력을 만들면 됐던 것.</p>
<br>

<p>#2</p>
<pre><code class="language-js">process.stdin.setEncoding(&#39;utf8&#39;);
process.stdin.on(&#39;data&#39;, data =&gt; {
    const n = data.split(&quot; &quot;);
    const a = Number(n[0]), b = Number(n[1]);
    console.log(((&#39;*&#39;).repeat(a)+`\n`).repeat(b))
});</code></pre>
<p>풀이
혹은 더 간결하게 한 줄로 끝낼 수도 있었다.</p>
<hr>
<h3 id="🤦-오늘의-문제-핥짝-2">🤦 오늘의 문제 핥짝 #2</h3>
<blockquote>
<p><strong>[프로그래머스]</strong> Lv2: JadenCase 문자열 만들기</p>
</blockquote>
<p><strong>문제 설명</strong> 
JadenCase란 모든 단어의 첫 문자가 대문자이고, 그 외의 알파벳은 소문자인 문자열입니다. 단, 첫 문자가 알파벳이 아닐 때에는 이어지는 알파벳은 소문자로 쓰면 됩니다. (첫 번째 입출력 예 참고)
문자열 s가 주어졌을 때, s를 JadenCase로 바꾼 문자열을 리턴하는 함수, solution을 완성해주세요.</p>
<p><strong>제한사항</strong></p>
<ul>
<li>s는 길이 1 이상 200 이하인 문자열입니다.</li>
<li>s는 알파벳과 숫자, 공백문자(&quot; &quot;)로 이루어져 있습니다.<ul>
<li>숫자는 단어의 첫 문자로만 나옵니다.</li>
<li>숫자로만 이루어진 단어는 없습니다.</li>
<li>공백문자가 연속해서 나올 수 있습니다.</li>
</ul>
</li>
</ul>
<p><strong>입출력 예</strong></p>
<table>
<thead>
<tr>
<th align="center">s</th>
<th align="center">return</th>
</tr>
</thead>
<tbody><tr>
<td align="center">&quot;3people unFollowed me&quot;</td>
<td align="center">&quot;3people Unfollowed Me&quot;</td>
</tr>
<tr>
<td align="center">&quot;for the last week&quot;</td>
<td align="center">&quot;For The Last Week&quot;</td>
</tr>
</tbody></table>
<hr>
<h3 id="나의-풀이-1">나의 풀이</h3>
<pre><code class="language-js">function solution(s) {
  var answer = s.split(&quot; &quot;).map((e) =&gt; e[0].toUpperCase());

  return answer;
}

console.log(solution(&quot;3people unFollowed me&quot;));</code></pre>
<p><strong>구현 접근</strong></p>
<ol>
<li>해당 입력된 문자열을 단어별로 나누기 위해 split메소드에 인자를 공백을 포함하여 나누어 줌.</li>
<li>map 메소드를 통해 element의 [0] 인덱스에 속하는 값들을 대문자로 변환하는 메소드 toUpperCase()사용.</li>
<li>하지만 반환 값은 대문자로 변환된 <strong>3, U, M</strong> 만 결과값 반환.</li>
<li>뒤에 문자열은 어떻게 붙여서 오면 좋을지 고민하다 gpt에게 물어보게 됐다.<img src = https://velog.velcdn.com/images/woo_7i/post/60de14ac-0667-4c6d-9d6a-1fd64d109c3e/image.png width = "80%">

</li>
</ol>
<p>해당 질문을 통해 뒤에 문자열 까지 붙어서 결과값을 반환하게 되는 것을 확인한 후.
&quot;그럼 붙어오는 문자열들은 소문자로 오게되면 문제가 해결 되겠네?&quot;
싶어서 slice(1)뒤에 .toLowerCase() 함수를 적용해보았다.</p>
<pre><code class="language-js">function solution(s) {
  var answer = s
    .split(&quot; &quot;)
    .map((e) =&gt; e[0].toUpperCase() + e.slice(1).toLowerCase());

  return answer.join(&quot; &quot;);
} </code></pre>
<p>결과적으로 구현이 제대로 작동되는 것을 확인 할 수 있었다!
흡족한 상태로 제출을 하였으나</p>
<p><strong>하였으나,,!</strong></p>
<img src = https://velog.velcdn.com/images/woo_7i/post/7c9f63df-835b-4dde-973e-afdae3d9e353/image.png width = "80%">

<p>수 없이 쏟아지는 런타임 에러들.. 왜 나는 것인지 결국 이해할 수 없어 질문하기 코너에 들어가 같은 질문이 있는 것을 보고 아차하게 됐다.</p>
<img src = https://velog.velcdn.com/images/woo_7i/post/9cddb172-021e-4c13-a69a-517a4ebb919d/image.png width = "80%">
<img src = https://velog.velcdn.com/images/woo_7i/post/7075830b-1c2c-49bd-86b7-7491bef8a82c/image.png witdh ="70%">
다행이 같은 질문을 하신 분이 계셨었고,

<p>그 이유가 테스트 케이스의 인자 중 연속된 빈 문자열이 오게 된다면 split 메소드가 값을 반환하지 못 해 undefined 때문에 런타임 에러가 생긴다고 한다.</p>
<p>그렇게 최종적으로 답변을 참고하여 수정하게 된 코드는</p>
<pre><code class="language-js">function solution(s) {
  let answer = s
    .split(&quot; &quot;)
    .map((e) =&gt; (e ? e[0].toUpperCase() + e.slice(1).toLowerCase() : &quot;&quot;));

  return answer.join(&quot; &quot;);
}</code></pre>
<p>물론 스스로 작성한 답변 보다는 도움을 받은 것이 많다고 느끼지만 접근 시도를 map을 통하여 할 수 있을까라는 시작부터 할 수 있다는 것에서 조금의 만족을 하게 됐다.</p>
<p>다음 부터는 저런 질문에 답변을 할 수 있을 정도의 실력까지 길러보자!</p>
<hr>
<h3 id="다른-사람-풀이-1">다른 사람 풀이</h3>
<p>#1</p>
<pre><code class="language-js">function solution(s) {
    return s.split(&quot; &quot;).map(v =&gt; v.charAt(0).toUpperCase() + v.substring(1).toLowerCase()).join(&quot; &quot;);
}</code></pre>
<p>풀이</p>
<ol>
<li>map이 순회하는 해당 element의 0번째 인덱스를 추출만 하는 것이 아닌 charAt 메소드를 통해 인자의 테스트가 통과하지 못 하면 빈 문자열이 반환되게 설정 한 것.</li>
</ol>
<p><a href="https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/String/charAt">MDN 표준내장객체 String.prototype.charAt()</a></p>
<blockquote>
<p>charAt() 함수는 문자열에서 특정 인덱스에 위치하는 유니코드 단일문자를 반환합니다.
<br> <strong>구문</strong>
<code>str.charAt(index)</code>
<br> <strong>매개변수</strong></p>
</blockquote>
<ul>
<li>0과 문자열의 길이 - 1 사이의 정수값.</li>
<li>인자를 생략하면 기본값으로 0를 설정되고 첫 문자를 반환한다.
<br><code>index</code>
** 반환 값**<ul>
<li>지정된 인덱스에 해당하는 유니코드 단일문자를 반환한다.</li>
<li>만약 인덱스가 문자열 길이보다 큰 경우 빈 문자열 (예) &quot; &quot; 을 반환한다.</li>
</ul>
</li>
</ul>
<p>이렇게 또 메소드 하나를 배워갑니다.</p>
<hr>
<h3 id="🤦-오늘의-문제-핥짝-3">🤦 오늘의 문제 핥짝 #3</h3>
<blockquote>
<p><strong>[프로그래머스]</strong> Lv1: 최대공약수와 최소공배수</p>
</blockquote>
<p><strong>문제 설명</strong> 
두 수를 입력받아 두 수의 최대공약수와 최소공배수를 반환하는 함수, solution을 완성해 보세요. 배열의 맨 앞에 최대공약수, 그다음 최소공배수를 넣어 반환하면 됩니다. 예를 들어 두 수 3, 12의 최대공약수는 3, 최소공배수는 12이므로 solution(3, 12)는 [3, 12]를 반환해야 합니다.</p>
<p><strong>제한사항</strong></p>
<ul>
<li>두 수는 1이상 1000000이하의 자연수입니다.</li>
</ul>
<p><strong>입출력 예</strong></p>
<table>
<thead>
<tr>
<th align="center">n</th>
<th align="center">m</th>
<th align="center">return</th>
</tr>
</thead>
<tbody><tr>
<td align="center">3</td>
<td align="center">12</td>
<td align="center">[3, 12]</td>
</tr>
<tr>
<td align="center">2</td>
<td align="center">5</td>
<td align="center">[1, 10]</td>
</tr>
</tbody></table>
<hr>
<h3 id="나의-풀이-2">나의 풀이</h3>
<pre><code class="language-js">수학 공식을 통한,, 알고리즘,, 너무나 괴로웠다,, 
수학을 손 놓은지 오래돼서 그런지 아무것도 할 수 없는 자신이 
한탄 스럽기만 했다 그렇게 풀이를 알아보게 됐고
유클리드 호제 법이라는 알고리즘을 알게 됐다!</code></pre>
<p>그 풀이는</p>
<pre><code class="language-js">function solution(n, m) {
  var answer = [];
  const greatest = (a, b) =&gt; {
    if (b === 0) return a;
    return greatest(b, a % b);
  };
  const least = (a, b) =&gt; (a * b) / greatest(a, b);
  return [greatest(n, m), least(n, m)];
}</code></pre>
<p><a href="https://velog.io/@qmasem/%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%A8%B8%EC%8A%A4-%EC%B5%9C%EB%8C%80%EA%B3%B5%EC%95%BD%EC%88%98%EC%99%80-%EC%B5%9C%EC%86%8C-%EA%B3%B5%EB%B0%B0%EC%88%98-%EC%9E%90%EB%B0%94%EC%8A%A4%ED%81%AC%EB%A6%BD%ED%8A%B8">출처 velog</a></p>
<ol>
<li>최대공약수를 구하는 알고리즘 유클리드 호제법을 이용하여 최대공약수를 구합니다.
유클리드 호제법이란 주어진 인풋 중 큰 값을 a, 작은 값은 b, a를 b로 나눈 나머지를 r이라고 가정한다면,<pre><code>a &gt; b, a % b .. r 
b % r .. r2
r % r2 .. r3
</code></pre></li>
</ol>
<p>위 과정을 반복하다보면 나머지가 0이 되는 순간이 옵니다.
나머지를 0으로 만들어 주는 나눠주는 수가 최대 공약수가 됩니다.</p>
<pre><code>&lt;br&gt;
2. 위 과정을 반복하다보면 나머지가 0이 되는 순간이 옵니다.
나머지를 0으로 만들어 주는 나눠주는 수가 최대 공약수가 됩니다.

--- 
### 다른 사람 풀이
#1
```js
function gcdlcm(a, b) {
    var r;
    for(var ab= a*b;r = a % b;a = b, b = r){}
    return [b, ab/b];
}
</code></pre><p>풀이
for문 안의 조건을 기본 공식이 아닌, 반복하고자 하는 조건들의
변수를 다양하게 선언 가능하다는 것을 알게 됐다.
<img src = https://velog.velcdn.com/images/woo_7i/post/da63978a-bb38-4720-a302-9b3f73322e84/image.png width="80%"></p>
<h3 id="😮💨-정리">😮‍💨 정리</h3>
<p>이번에 배우게 된 유클리드 호제법과 for문의 조건 변형에 대해 잘 익혀두고 다음에는 응용하여 문제를 해결할 수 있게 이해를 익혀놓자!</p>
]]></description>
        </item>
        <item>
            <title><![CDATA[🟣 오늘의 문제 회고]]></title>
            <link>https://velog.io/@woo_7i/%EC%98%A4%EB%8A%98%EC%9D%98-%EB%AC%B8%EC%A0%9C-%ED%9A%8C%EA%B3%A0-en0424jb</link>
            <guid>https://velog.io/@woo_7i/%EC%98%A4%EB%8A%98%EC%9D%98-%EB%AC%B8%EC%A0%9C-%ED%9A%8C%EA%B3%A0-en0424jb</guid>
            <pubDate>Thu, 30 Mar 2023 10:03:03 GMT</pubDate>
            <description><![CDATA[<h3 id="😃-오늘의-문제-핥짝-1">😃 오늘의 문제 핥짝 #1</h3>
<blockquote>
<p><strong>[프로그래머스]</strong> Lv1: 부족한 금액 계산하기</p>
</blockquote>
<p><strong>문제 설명</strong> 
새로 생긴 놀이기구는 인기가 매우 많아 줄이 끊이질 않습니다. 이 놀이기구의 원래 이용료는 price원 인데, 놀이기구를 N 번 째 이용한다면 원래 이용료의 N배를 받기로 하였습니다. 즉, 처음 이용료가 100이었다면 2번째에는 200, 3번째에는 300으로 요금이 인상됩니다.
놀이기구를 count번 타게 되면 현재 자신이 가지고 있는 금액에서 얼마가 모자라는지를 return 하도록 solution 함수를 완성하세요.
단, 금액이 부족하지 않으면 0을 return 하세요.</p>
<p><strong>제한사항</strong></p>
<ul>
<li>놀이기구의 이용료 price : 1 ≤ price ≤ 2,500, price는 자연수</li>
<li>처음 가지고 있던 금액 money : 1 ≤ money ≤ 1,000,000,000, money는 자연수</li>
<li>놀이기구의 이용 횟수 count : 1 ≤ count ≤ 2,500, count는 자연수</li>
</ul>
<p><strong>입출력 예</strong></p>
<table>
<thead>
<tr>
<th align="center">price</th>
<th align="center">money</th>
<th align="center">count</th>
<th align="center">result</th>
</tr>
</thead>
<tbody><tr>
<td align="center">3</td>
<td align="center">20</td>
<td align="center">4</td>
<td align="center">10</td>
</tr>
</tbody></table>
<hr>
<h3 id="나의-풀이">나의 풀이</h3>
<pre><code class="language-js">function solution(price, money, count) {
  var answer = money;
  let sumPrice = 0;
  for (let i = 1; i &lt;= count; i++) {
    sumPrice += price * i;
  }
  return sumPrice - answer &lt;= 0 ? 0 : sumPrice - answer;
}</code></pre>
<p><strong>구현 접근</strong></p>
<ol>
<li>count 만큼 증가되는 price의 총합을 sumPrice에 할당</li>
<li>sumPrice - answer 해서 금액이 모자라지 않는다면 0을 반환</li>
<li>그렇지 않으며 부족한 만큼의 돈을 반환을 삼항 연산으로 풀이.</li>
</ol>
<hr>
<h3 id="다른-사람-풀이">다른 사람 풀이</h3>
<p>#1</p>
<pre><code class="language-js">function solution(price, money, count) {
    const tmp = price * count * (count + 1) / 2 - money;
    return tmp &gt; 0 ? tmp : 0;
}</code></pre>
<p>풀이
가우스 공식에 의한 풀이 공식.
<a href="https://blog.naver.com/goodlook459/222701832951">가우스 공식|작성자 windrew</a> </p>
<blockquote>
<p><code>가우스 공식이란</code> : 등차수열의 합 가우스는 1부터 100까지의 합을 구할 때 1<del>100에 100</del>1까지 순서로 다시 더한 다음 2로 나누어 합을 구하는 방식을 사용했다.
1부터 100까지의 합을 S로 두면
S = 1 + 2 + 3 + 4 + 5 + 6 + ... + 99 + 100
S = 100 + 99 + 98 + 97 + 96 + 95 + 94 + ... +2 + 1
이므로
2S = 101 * 100이다.
그러므로
S = 101 * 50 = 5050이다.
이걸 n에 대해 확장하면 1부터 n까지의 합은 (n+1)*n/2인 것을 알 수 있고,
일반적인 두 자연수  a,b(a&lt;=b)에 대해서 a부터 b까지의 자연수의 합은 (a+b)(b-a+1)/2인 것도 쉽게 알 수 있다.
이제 얘를 유용하게 써먹을 문제를 찾아서 써먹으면 된다.</p>
</blockquote>
<p>#2</p>
<pre><code class="language-js">function solution(price, money, count) {
    let answer = 0;

    for (let i = 1; i &lt;= count; i++) {
        answer += price * i;
    }

    return answer &gt; money ? answer - money : 0;
}</code></pre>
<p>풀이 
굳이 price를 합한 값을 새로운 변수에 할당하여 삼항연산자를 이용할 필요가 없었다.</p>
<hr>
<h3 id="😃-오늘의-문제-핥짝-2">😃 오늘의 문제 핥짝 #2</h3>
<blockquote>
<p><strong>[프로그래머스]</strong> Lv2: 최댓값과 최솟값</p>
</blockquote>
<p><strong>문제 설명</strong> 
문자열 s에는 공백으로 구분된 숫자들이 저장되어 있습니다. str에 나타나는 숫자 중 최소값과 최대값을 찾아 이를 &quot;(최소값) (최대값)&quot;형태의 문자열을 반환하는 함수, solution을 완성하세요.
예를들어 s가 &quot;1 2 3 4&quot;라면 &quot;1 4&quot;를 리턴하고, &quot;-1 -2 -3 -4&quot;라면 &quot;-4 -1&quot;을 리턴하면 됩니다.</p>
<p><strong>제한사항</strong></p>
<ul>
<li>s에는 둘 이상의 정수가 공백으로 구분되어 있습니다.</li>
</ul>
<p><strong>입출력 예</strong></p>
<table>
<thead>
<tr>
<th align="center">price</th>
<th align="center">result</th>
</tr>
</thead>
<tbody><tr>
<td align="center">&quot;1 2 3 4&quot;</td>
<td align="center">&quot;1 4&quot;</td>
</tr>
<tr>
<td align="center">&quot;-1 -2 -3 -4&quot;</td>
<td align="center">&quot;-4 -1&quot;</td>
</tr>
<tr>
<td align="center">&quot;-1 -1&quot;</td>
<td align="center">&quot;-1 -1&quot;</td>
</tr>
</tbody></table>
<hr>
<h3 id="나의-풀이-1">나의 풀이</h3>
<pre><code class="language-js">function solution(s) {
  var answer = s.split(&quot; &quot;);
  let max = Math.max(...answer);
  let min = Math.min(...answer);
  return min + &quot; &quot; + max;
}</code></pre>
<p><strong>구현 접근</strong></p>
<ol>
<li>split 메소드를 이용하여 해당 공백을 포함한 문자열을 반환.</li>
<li>max 변수와 min 변수 선언 후 Math.max,min 메소드 활용.</li>
<li>메소드의 인자로 스프레드 문법 배열을 할당하면 해당 배열이 전부 인자로 할당.</li>
<li>&quot; &quot;, 공백 따옴표를 더해줌으로써 해당 min값과 max값을 따로 반환.</li>
</ol>
<hr>
<h3 id="다른-사람-풀이-1">다른 사람 풀이</h3>
<p>#1</p>
<pre><code class="language-js">function solution(s) {
    const arr = s.split(&#39; &#39;);

    return Math.min(...arr)+&#39; &#39;+Math.max(...arr);
}</code></pre>
<p>풀이</p>
<ol>
<li>return을 통해 한줄로 코드를 개선이 가능하더라,,</li>
</ol>
<br>

<p>#2</p>
<pre><code class="language-js">function solution(s) {
    var arr = s.split(&#39; &#39;);
    arr.sort((a, b) =&gt; a - b);

    var answer = arr[0] + &quot; &quot; + arr[arr.length-1];

    return answer;
}</code></pre>
<p>풀이 </p>
<ol>
<li>sort를 적용하여 해당 공백을 포함한 배열을 정렬.</li>
<li>대괄호를 통해 정렬 된 배열의 인덱스를 불러와 &quot; &quot;을 포함한 값을 연산.</li>
</ol>
<hr>
<h3 id="😃-오늘의-문제-핥짝-3">😃 오늘의 문제 핥짝 #3</h3>
<blockquote>
<p><strong>[프로그래머스]</strong> Lv1 : 행렬의 덧셈</p>
</blockquote>
<p><strong>문제 설명</strong> 
행렬의 덧셈은 행과 열의 크기가 같은 두 행렬의 같은 행, 같은 열의 값을 서로 더한 결과가 됩니다. 2개의 행렬 arr1과 arr2를 입력받아, 행렬 덧셈의 결과를 반환하는 함수, solution을 완성해주세요.</p>
<p><strong>제한사항</strong></p>
<ul>
<li>행렬 arr1, arr2의 행과 열의 길이는 500을 넘지 않습니다.</li>
</ul>
<p><strong>입출력 예</strong></p>
<table>
<thead>
<tr>
<th align="center">arr1</th>
<th align="center">arr2</th>
<th align="center">return</th>
</tr>
</thead>
<tbody><tr>
<td align="center">[[1,2],[2,3]]</td>
<td align="center">[[3,4],[5,6]]</td>
<td align="center">[[4,6],[7,9]]</td>
</tr>
<tr>
<td align="center">[[1],[2]]</td>
<td align="center">[[3],[4]]</td>
<td align="center">[[4],[6]]</td>
</tr>
</tbody></table>
<hr>
<h3 id="나의-풀이-2">나의 풀이</h3>
<pre><code class="language-js">function solution(arr1, arr2) {
  var answer = [];
  for (let i = 0; i &lt; arr1.length; i++) {
    let sum = [];
    for (let j = 0; j &lt; arr1[i].length; j++) {
      sum.push(arr1[i][j] + arr2[i][j]);
    }
    answer.push(sum);
  }
  return answer;
}</code></pre>
<p><strong>구현 접근</strong></p>
<ol>
<li>다차원 배열을 통한 배열별 인덱스 합을 구해야 했기에 2중 for문 사용</li>
<li>빈 배열 sum에다 각 배열이 갖는 인덱스 별로 합을 준 값을 push.</li>
<li>또 각각 푸쉬 된 배열을 answer에 푸쉬.</li>
</ol>
<p><a href="https://ko.javascript.info/array">출처 : 자바스크립트 info</a>
<img src = https://velog.velcdn.com/images/woo_7i/post/501fc0f4-ad8c-4aed-b52f-a04693c1b1be/image.png width="80%"></p>
<hr>
<h3 id="다른-사람-풀이-2">다른 사람 풀이</h3>
<p>#1</p>
<pre><code class="language-js">function sumMatrix(A,B){
    return A.map((arr1, idx1) =&gt; arr1.map((val, idx2) =&gt; val+B[idx1][idx2]));
}</code></pre>
<p>풀이</p>
<ol>
<li>map 메소드를 두번 적용하여 반복문을 만들었다. 
대체 이런 코드는 어떻게 작성할 수 있는 것인가,,</li>
</ol>
<p>구체적인 이해가 필요해서 gpt에게 물어봤다.
<img src =https://velog.velcdn.com/images/woo_7i/post/3ccf25f1-a92d-478e-b485-1502672473f9/image.png width= "80%">
이 과정을 이해하고 나서 다음 과정 때 써먹을 수 있으면 좋겠군,</p>
<p>#2</p>
<pre><code class="language-js">function solution(arr1, arr2) {
    var answer = [[]];
    for (var i=0; i&lt;arr1.length; i++){
        answer[i] =[];
        for(var j=0; j&lt;arr1[i].length; j++){
            answer[i].push(arr1[i][j] + arr2[i][j]);
        }
    }
    return answer;
}</code></pre>
<p>풀이</p>
<ol>
<li>위 코드 역시 2중 for문을 통해 인덱스 별 인덱스의 값을 더해 push 하는 것.</li>
<li>그러나 나 처럼 sum 빈배열을 만드는 것이 아닌 해당 담아야 할 인덱스 자체에 빈배열을 만드는 것.</li>
</ol>
<p>지금의 코드가 더 간결하게 이해가 되는 것 같다.</p>
]]></description>
        </item>
        <item>
            <title><![CDATA[🟣 오늘의 문제 회고]]></title>
            <link>https://velog.io/@woo_7i/%EC%98%A4%EB%8A%98%EC%9D%98-%EB%AC%B8%EC%A0%9C-%ED%9A%8C%EA%B3%A0-relb5czg</link>
            <guid>https://velog.io/@woo_7i/%EC%98%A4%EB%8A%98%EC%9D%98-%EB%AC%B8%EC%A0%9C-%ED%9A%8C%EA%B3%A0-relb5czg</guid>
            <pubDate>Tue, 28 Mar 2023 10:57:18 GMT</pubDate>
            <description><![CDATA[<h3 id="😃-오늘의-문제-핥짝-1">😃 오늘의 문제 핥짝 #1</h3>
<blockquote>
<p><strong>[프로그래머스]</strong> Lv1: 문자열 내림차순으로 배치하기</p>
</blockquote>
<p><strong>문제 설명</strong> 
문자열 s에 나타나는 문자를 큰것부터 작은 순으로 정렬해 새로운 문자열을 리턴하는 함수, solution을 완성해주세요.
s는 영문 대소문자로만 구성되어 있으며, 대문자는 소문자보다 작은 것으로 간주합니다.</p>
<p><strong>제한사항</strong>
str은 길이 1 이상인 문자열입니다.</p>
<p><strong>입출력 예</strong></p>
<table>
<thead>
<tr>
<th align="center">s</th>
<th align="center">return</th>
</tr>
</thead>
<tbody><tr>
<td align="center">&quot;Zbcdefg&quot;</td>
<td align="center">&quot;gfedcbZ&quot;</td>
</tr>
</tbody></table>
<hr>
<h3 id="나의-풀이">나의 풀이</h3>
<pre><code class="language-js">function solution(s) {
  var answer = s
    .split(&quot;&quot;)
    .sort((a, b) =&gt; a - b)
    .reverse()
    .join(&quot;&quot;);
  return answer;
}</code></pre>
<p><strong>구현 접근</strong></p>
<ol>
<li>해당 문자열을 나누어 배열로 반환하기 위해 split 메소드 사용</li>
<li>sort 메소드를 이용하여 두 인자를 비교 후 오름차순으로 나열</li>
<li>위 조건에서 대문자가 가장 작은 값으로 반환하기 위해 reverse 메소드를 사용하여 해당 문자열의 오름차순을 역순으로 나타냈다.</li>
</ol>
<p><strong>문제점</strong></p>
<ol>
<li>해당 함수에서 조건의 입출력은 통과가 되지만 테스트 케이스에서 통과가 되지 못 하는 문제가 생김.</li>
<li>문자열에서 sort는 ascii 코드의 유니코드 표기 값으로 비교가 이뤄지는데 
sort 메소드의 인자로 주어진 a - b 연산은 숫자 형만 가능.
a-b로 연산 된 값이 0을 기준으로 작거나 커야 차순 정렬이 이뤄진다.</li>
</ol>
<p>그러나 문자열은 연산이 불가능 하며, 문자열은 인자의 (a-b)의 연산으로 참 거짓을 나눌 수 있는 비교 성립자체가 불가. </p>
<p>유니코드의 숫자 표기 크기를 통해 비교를 하기 때문에 비교연산자를 사용하거나, localeCompare( )메서드를 통해 대소 비교를 해주어야 한다.</p>
<p>그 이유는 아래 예시를 참고하자.
<em>sort 기능 예시)</em>
<img src= https://velog.velcdn.com/images/woo_7i/post/09a80e6e-fac7-4cec-ad4b-a514003bbef1/image.png></p>
<img src= https://velog.velcdn.com/images/woo_7i/post/acf1588c-cd60-45c4-ade2-f58c24b6cf13/image.png>



<p>그렇기에 문자열 자체를 차순 정렬하고 싶으면 2가지 방법이 존재한다.</p>
<p><code>크기를 비교한 값의 조건을 통해 -1, 0, 1 값중 하나로 반환 후 정렬.</code></p>
<ol>
<li>문자열 배열 비교 연산자를 통한 오름차순 정렬<pre><code class="language-js">sort((a, b) =&gt; {
 return a &lt; b ? -1 : a &gt; b ? 1 : 0;
})</code></pre>
</li>
</ol>
<ol start="2">
<li>문자열 배열 비교 연산자를 통한 내림차순 정렬<pre><code class="language-js">sort((a, b) =&gt; {
   return a &gt; b ? -1 : a &lt; b ? 1 : 0;
 })</code></pre>
</li>
</ol>
<p><code>String.prototype.localeCompare() 메소드 이용</code></p>
<p>localeCompare() 메서드는 참조 문자열이 정렬 순으로 지정된 문자열 앞 혹은 뒤에 오는지 또는 동일한 문자열인지 나타내는 수치를 반환합니다.</p>
<ol>
<li><p>localeCompare( ) 오름차순 정렬</p>
<pre><code class="language-js">sort((a, b) =&gt; a.localeCompare(b))</code></pre>
</li>
<li><p>localeCompare( ) 내림차순 정렬</p>
<pre><code class="language-js">sort((a, b) =&gt; b.localeCompare(a))</code></pre>
</li>
</ol>
<p><code>그러나 위의 두 식에도 차이가 존재하는데, 예시 코드를 살펴보자면</code></p>
<pre><code class="language-js">var str = &quot;Zbcdefg&quot;;
var split = str.split(&quot;&quot;);

console.log(split.sort((a, b) =&gt; {
      return a &lt; b ? -1 : a &gt; b ? 1 : 0;
    }).join(&quot;&quot;));

console.log(split.sort((a, b) =&gt; {
      return a &gt; b ? -1 : a &lt; b ? 1 : 0;
    }).join(&quot;&quot;));

console.log(split.sort((a, b) =&gt; a.localeCompare(b)).join(&quot;&quot;));
console.log(split.sort((a, b) =&gt; b.localeCompare(a)).join(&quot;&quot;));

// 아스키 코드 숫자의 비교 값에 따라 차순 정렬 적용.
Zbcdefg  
gfedcbZ

// 문자 사전 순서 그대로 차순 정렬 적용.
bcdefgZ
Zgfedcb</code></pre>
<hr>
<p>sort() 메소드 기능 자체에 다시금 살펴볼 수 있는 계기가 되었고 gpt 도움과 구글 검색을 통해서 무엇이 문제인지 sort 메소드에 좀 더 다가갈 수있었다.</p>
<p>map을 통해 sort 메소드를 정렬하는 방법도 있었는데 차후 이해하도록 해보쟈,, </p>
<hr>
<h3 id="다른-사람-풀이">다른 사람 풀이</h3>
<p>#1</p>
<pre><code class="language-js">  function solution(s) {
  return s
    .split(&quot;&quot;)
    .sort()
    .reverse()
    .join(&quot;&quot;);
}</code></pre>
<p>풀이</p>
<ol>
<li>문자열 sort할 때는 localeCompare을 이용하거나</li>
<li>sort([compareFunction]) 인자 값으로 아무것도 전달하지 않으면 얻고자 하는 정렬이 될 것이다,,!</li>
</ol>
<p>#2</p>
<pre><code class="language-js">  function solution(s) {
    return s.split(&quot;&quot;).sort((a,b) =&gt; a&lt;b ? 1:-1).join(&quot;&quot;)
}</code></pre>
<p>풀이</p>
<ol>
<li>비교 조건을 통해 얻은 결과 값으로 정렬하는 방법을 사용하셨다..! </li>
</ol>
<hr>
<h3 id="😃-오늘의-문제-핥짝-2">😃 오늘의 문제 핥짝 #2</h3>
<blockquote>
<p>약수의 개수와 덧셈</p>
</blockquote>
<p><strong>문제 설명</strong> 
두 정수 left와 right가 매개변수로 주어집니다. left부터 right까지의 모든 수들 중에서, 약수의 개수가 짝수인 수는 더하고, 약수의 개수가 홀수인 수는 뺀 수를 return 하도록 solution 함수를 완성해주세요.</p>
<p><strong>제한사항</strong>
1 ≤ left ≤ right ≤ 1,000</p>
<p><strong>입출력 예</strong></p>
<table>
<thead>
<tr>
<th align="center">left</th>
<th align="center">right</th>
<th align="center">result</th>
</tr>
</thead>
<tbody><tr>
<td align="center">13</td>
<td align="center">17</td>
<td align="center">43</td>
</tr>
<tr>
<td align="center">24</td>
<td align="center">27</td>
<td align="center">52</td>
</tr>
</tbody></table>
<hr>
<h3 id="나의-풀이-1">나의 풀이</h3>
<pre><code class="language-js">  function collect(num) {
  let sum = 0;
  for (let i = 1; i &lt;= num; i++) {
    if (num % i === 0) sum += 1;
  }
  return sum;
}

function solution(left, right) {
  let answer = 0;
  for (let i = left; i &lt;= right; i++) {
    collect(i) % 2 === 0 ? (answer += i) : (answer -= i);
  }
  return answer;
}</code></pre>
<p><strong>구현 접근</strong></p>
<ol>
<li>collect 함수를 통해 해당 인자에 대입되는 값의 약수가 몇개인지 구하고</li>
<li>solution 함수를 통해 left에서 right의 범위까지 숫자들의 약수가 짝수 값이면 더하고 홀수 값이면 빼는 함수 기능을 구현.</li>
</ol>
<p><strong>문제점</strong>
하나의 함수만으로 문제를 해결하려하지 말고 다양한 함수를 통해 얻고자 하는 결과 값을 반환하자.
위의 코드에서는 약수 개수를 파악하는 함수와
파악한 개수를 홀, 짝 구별하여 합산하는 함수를 구현해야 했다.</p>
<hr>
<h3 id="다른-사람-풀이-1">다른 사람 풀이</h3>
<p>#1</p>
<pre><code class="language-js">  function solution(left, right) {
  let answer = 0;

  for (let i = left; i &lt;= right; i++) {
    let count = 0;
    for (let j = 1; j &lt;= i; j++) {
      if (i % j === 0) count++; // 약수의 개수 누산
    }
    if (count % 2)
      answer -= i; // 전체 약수의 개수를 2로 나눈 나머지가 존재하면 뺀 값을 할당
    else answer += i; // 전체 약수의 개수를 2로 나눈 나머지가 존재하지 않으면 더한 값을 할당
  }

  return answer;
}
</code></pre>
<p>풀이
이중 for문으로 구현 해보고 싶었는데 구현 하신 분이 계셔서 가져와봤다.</p>
<ol>
<li>answer의 for 문으로 count의 값을 구해 홀,짝 구별 후 조건 합산</li>
<li>count의 for 문으로 약수의 개수가 몇개인지 누산.</li>
</ol>
<p>#2</p>
<pre><code class="language-js">  function solution(left, right) {
    var answer = 0;
    for (let i = left; i &lt;= right; i++) {
        if (Number.isInteger(Math.sqrt(i))) {
            answer -= i;
        } else {
            answer += i;
        }
    }
    return answer;
}</code></pre>
<p>풀이</p>
<ol>
<li>제곱근이 정수면 약수의 개수가 홀수다...</li>
</ol>
<hr>
<h3 id="😃-오늘의-문제-핥짝-3">😃 오늘의 문제 핥짝 #3</h3>
<blockquote>
<p>문자열 다루기 기본</p>
</blockquote>
<p><strong>문제 설명</strong> 
문자열 s의 길이가 4 혹은 6이고, 숫자로만 구성돼있는지 확인해주는 함수, solution을 완성하세요. 예를 들어 s가 &quot;a234&quot;이면 False를 리턴하고 &quot;1234&quot;라면 True를 리턴하면 됩니다.</p>
<p><strong>제한사항</strong></p>
<ul>
<li>s는 길이 1 이상, 길이 8 이하인 문자열입니다.</li>
<li>s는 영문 알파벳 대소문자 또는 0부터 9까지 숫자로 이루어져 있습니다.</li>
</ul>
<p><strong>입출력 예</strong></p>
<table>
<thead>
<tr>
<th align="center">s</th>
<th align="center">return</th>
</tr>
</thead>
<tbody><tr>
<td align="center">&quot;a234&quot;</td>
<td align="center">false</td>
</tr>
<tr>
<td align="center">&quot;1234&quot;</td>
<td align="center">true</td>
</tr>
</tbody></table>
<hr>
<h3 id="나의-풀이-2">나의 풀이</h3>
<pre><code class="language-js">  function solution(s) {
  var answer = s
    .split(&quot;&quot;)
    .map((e) =&gt; e * 1)
    .every((cur) =&gt; typeof cur === &quot;number&quot;);

  return answer;
}

console.log(solution(&quot;a234&quot;));</code></pre>
<p>  <strong>구현 접근</strong></p>
<ol>
<li>split 메소드를 통해 해당 문자열을 나누어 준 다음</li>
<li>map 메소들 통해 배열 엘리먼트를 각각 *1 연산하여 숫자형으로 형 변환을 해주었다.</li>
<li>마지막으로 every 메소드를 통해 각 조건이 통과가 되는지 판별하는 함수를 구현</li>
</ol>
<p>  <strong>문제점</strong></p>
<ol>
<li><p>typeof의 문제</p>
<pre><code class="language-js">cur = [&#39;a&#39;,&#39;2&#39;,&#39;3&#39;,&#39;4&#39;] 일 때
.every((cur) =&gt; typeof cur === Number);
// true</code></pre>
<p>지금 코드의 문제점은 type of에서 나오는 것이었다.</p>
<img src = https://velog.velcdn.com/images/woo_7i/post/9c41b6b1-a2d7-40c1-8f6d-779908286ecf/image.png >

<p>그러나 개선 후 every 메소드를 사용할 때 typeof의 결과 값이 &#39;number&#39;면 true를 반환하기를 바랬는데,,</p>
<p><code>cur = [&#39;a&#39;,&#39;2&#39;,&#39;3&#39;,&#39;4&#39;]</code>일 때도 true가 나오는 것 이었다.</p>
<p>console.log(cur)을 해보니 NaN이 나오는 것.
NaN은 typeof 하면 number로 취급.</p>
</li>
</ol>
<img src= https://velog.velcdn.com/images/woo_7i/post/2715df98-b06d-4228-b970-4ed6efb80684/image.png>

<p>문제 개선</p>
<ol>
<li>cur의 인자 값이 숫자로 변환이 가능한지 여부를 파악할 수 있는 함수 isNaN 메소드를 </li>
<li>every 메소드를 통해 순환하여 참 거짓 판별.</li>
</ol>
<hr>
<h3 id="다른-사람-풀이-2">다른 사람 풀이</h3>
<p>  #1</p>
<pre><code class="language-js">  function alpha_string46(s) {
   return s.length == 4 || s.length == 6 ? !isNaN(s) : false 
}</code></pre>
<p>풀이
s의 인자로 전달 되는 문자열이 숫자형 변환이 가능한지 삼항연산자로 한번에 여부 파악.</p>
<p>그러나 지금 코드의 문제점으로는 인자 값이 <strong>지수</strong>로 오게되면 테스트 케이스를 통과하지 못 한다. </p>
<pre><code class="language-js">  s = &quot;1e22&quot;</code></pre>
<p>나의 코드처럼 split으로 하나씩 쪼개어 구분하는 것도 방법이 될 것 같다.</p>
<p>  #2</p>
<pre><code class="language-js">  function alpha_string46(s){
    var regex = /^\d{6}$|^\d{4}$/;

  return regex.test(s);
}</code></pre>
<p>  풀이 
  정규 표현식 메소드 test를 사용하여 함수를 구현한 방식이다.
  정규 표현식은 아직 잘 다룰 줄 몰라 접근하기가 어려운 것 같다..</p>
]]></description>
        </item>
        <item>
            <title><![CDATA[🟣 오늘의 문제 회고]]></title>
            <link>https://velog.io/@woo_7i/%EC%98%A4%EB%8A%98%EC%9D%98-%EB%AC%B8%EC%A0%9C-%ED%9A%8C%EA%B3%A0-davnojub</link>
            <guid>https://velog.io/@woo_7i/%EC%98%A4%EB%8A%98%EC%9D%98-%EB%AC%B8%EC%A0%9C-%ED%9A%8C%EA%B3%A0-davnojub</guid>
            <pubDate>Mon, 27 Mar 2023 12:12:57 GMT</pubDate>
            <description><![CDATA[<h3 id="🧐-오늘의-문제-핥짝-1">🧐 오늘의 문제 핥짝 #1</h3>
<hr>
<blockquote>
<p><strong>[프로그래머스]</strong> Lv1: 가운데 글자 가져오기</p>
</blockquote>
<p><strong>문제 설명</strong> 
단어 s의 가운데 글자를 반환하는 함수, solution을 만들어 보세요. 단어의 길이가 짝수라면 가운데 두글자를 반환하면 됩니다.</p>
<p><strong>제한사항</strong></p>
<ul>
<li>s는 길이가 1 이상, 100이하인 스트링입니다.</li>
</ul>
<p><strong>입출력 예</strong></p>
<table>
<thead>
<tr>
<th align="center">s</th>
<th align="center">return</th>
</tr>
</thead>
<tbody><tr>
<td align="center">&quot;abcde&quot;</td>
<td align="center">&quot;c&quot;</td>
</tr>
<tr>
<td align="center">&quot;qwer&quot;</td>
<td align="center">&quot;w,e&quot;</td>
</tr>
</tbody></table>
<hr>
<h3 id="나의-풀이">나의 풀이</h3>
<pre><code class="language-js">function solution(s) {
  var sampleValue = Math.floor(s.length / 2);
  var answer = &quot;&quot;;
  // 단어 s의 가운데 글자를 반환하는 함수,
  // 단어의 길이가 짝수라면 가운데 두글자를 반환하면 됩니다.
  if (s.length % 2 != 1) answer = s.slice(sampleValue - 1, sampleValue + 1);
  else answer = s.slice(sampleValue, sampleValue + 1);
  return answer;
}</code></pre>
<p><strong>구현 접근</strong></p>
<ol>
<li>가운데 글자를 반환하기 위해 해당 문자열의 가운데 값을 알 수 있게 sampleValue 변수에 Math.floor 메소드를 이용하여 문자열 s의 길이를 2로 나눈 값을 주었다.</li>
<li>if조건을 통해 짝수, 홀수 판별 후 answer에다 slice 메소드를 이용하여 해당 문자열을 추출할 수 있게 함수를 구현함.</li>
</ol>
<p><strong>문제점</strong>
무언가 좀 더 코드를 깔끔하게 만들 순 없을까 다른 사람의 풀이를 보았는데 인상 깊었던 것은, 
문자열에 특정 글자에 접근하고 싶을 때, 문자열의 [인덱스]를 넣거나, (인덱스) 값을 넣으면 원하는 글자를 추출할 수 가 있었다.
(아래 출처: <a href="https://ko.javascript.info/string#ref-1142">자바스크립트 인포</a>)
<img src = https://velog.velcdn.com/images/woo_7i/post/47e27c55-3401-4e4c-b388-ef96d1971cca/image.png width ="70%"></p>
<hr>
<h3 id="다른-사람-풀이">다른 사람 풀이</h3>
<p>#1</p>
<pre><code class="language-js">function solution(s) {
    const mid = Math.floor(s.length/2);
    return s.length %2 === 1 ? s[mid] : s[mid-1]+s[mid];
}</code></pre>
<p>풀이</p>
<ol>
<li>floor 방식은 나와 같이 중간 값을 구하기 위한 방식인 것 같았고</li>
<li>삼항연산자의 조건을 통해서 해당하는 특정 글자를 얻기 위해 [ ]안에 나눈 변수를 할당하여 함수를 구현한 것이 내가 생각했을 때 가장 깔끔한 것 같았다. </li>
<li>짝수일 때 조건에 필요한 값을 + 연산자를 통해 문자열을 병합하여 2개를 얻어낸 것 역시 다름에 활용할 때 잘 사용하면 될 것 같다고 생각했다.</li>
</ol>
<hr>
<h3 id="🧐-오늘의-문제-핥짝-2">🧐 오늘의 문제 핥짝 #2</h3>
<blockquote>
<p><strong>[프로그래머스]</strong> Lv1: 수박수박수박수박수박수?</p>
</blockquote>
<p><strong>문제 설명</strong> 
길이가 n이고, &quot;수박수박수박수....&quot;와 같은 패턴을 유지하는 문자열을 리턴하는 함수, solution을 완성하세요. 예를들어 n이 4이면 &quot;수박수박&quot;을 리턴하고 3이라면 &quot;수박수&quot;를 리턴하면 됩니다.</p>
<p><strong>제한사항</strong></p>
<ul>
<li>n은 길이 10,000이하인 자연수입니다.</li>
</ul>
<p><strong>입출력 예</strong></p>
<table>
<thead>
<tr>
<th align="center">n</th>
<th align="center">return</th>
</tr>
</thead>
<tbody><tr>
<td align="center">3</td>
<td align="center">&quot;수박수&quot;</td>
</tr>
<tr>
<td align="center">4</td>
<td align="center">&quot;수박수박&quot;</td>
</tr>
</tbody></table>
<hr>
<h3 id="나의-풀이-1">나의 풀이</h3>
<pre><code class="language-js">function solution(n) {
  var repeat = &quot;수박&quot;;
  var answer = repeat.repeat(n).slice(0, n);
  return answer;
}</code></pre>
<p><strong>구현 접근</strong></p>
<ol>
<li>해당 문자열이 반복을 해야하니 그만큼 반복할 수 있게 repeat 메소드를 사용함.</li>
<li>answer에다 해당 문자열 만큼 잘라준다면 원하는 길이만큼의 반복된 문자열이 반환 됨.</li>
</ol>
<p><strong>학습</strong>
<strong>substring() 메소드</strong>는 string 객체의 시작 인덱스로 부터 종료 인덱스 전 까지 문자열의 부분 문자열을 반환합니다.</p>
<p><strong>slice() 메소드</strong>는 문자열의 일부를 추출하면서 새로운 문자열을 반환합니다.
같은 맥락이지만 substring 메소드도 이와 같은 기능으로써 사용할 수 있음을 인지하고 있자.</p>
<hr>
<h3 id="🧐-오늘의-문제-핥짝-3">🧐 오늘의 문제 핥짝 #3</h3>
<blockquote>
<p><strong>[프로그래머스]</strong> Lv1: 내적</p>
</blockquote>
<p><strong>문제 설명</strong> 
길이가 같은 두 1차원 정수 배열 a, b가 매개변수로 주어집니다. a와 b의 내적을 return 하도록 solution 함수를 완성해주세요.</p>
<p>이때, a와 b의 내적은 a[0]<em>b[0] + a[1]</em>b[1] + ... + a[n-1]*b[n-1] 입니다. (n은 a, b의 길이)</p>
<p><strong>제한사항</strong></p>
<ul>
<li>a, b의 길이는 1 이상 1,000 이하입니다.</li>
<li>a, b의 모든 수는 -1,000 이상 1,000 이하입니다.</li>
</ul>
<p><strong>입출력 예</strong></p>
<table>
<thead>
<tr>
<th align="center">a</th>
<th align="center">b</th>
<th align="center">result</th>
</tr>
</thead>
<tbody><tr>
<td align="center">[1,2,3,4]</td>
<td align="center">[-3,-1,0,2]</td>
<td align="center">3</td>
</tr>
<tr>
<td align="center">[-1,0,1]</td>
<td align="center">[1,0,-1]</td>
<td align="center">-2</td>
</tr>
</tbody></table>
<hr>
<h3 id="나의-풀이-2">나의 풀이</h3>
<pre><code class="language-js">function solution(a, b) {
  var answer = [];
  for (let i = 0; i &lt; a.length; i++) {
    answer.push(a[i] * b[i]);
  }
  return answer.reduce((a, c) =&gt; a + c, 0);
}</code></pre>
<p><strong>구현 접근</strong></p>
<ol>
<li>각 인자별 배열을 순회하며 같은 짝끼리 곱을 해줘야 했기에 for을 통해 인덱스 별로 곱을 했음.</li>
<li>곱한 값을 answer에 push</li>
<li>push된 배열을 reduce 함수를 통해 모두 더해 주었다.</li>
</ol>
<p><strong>문제점</strong> </p>
<ol>
<li>굳이 reduce를 사용하지 않아도 가능한 순회였다.
for를 사용하던지 reduce만 사용하던지 가능한 함수였다.</li>
</ol>
<p>다른 사람 풀이를 보면서 어떤 문제였는지 살펴보자.</p>
<h3 id="다른-사람-풀이-1">다른 사람 풀이</h3>
<hr>
<p>#1</p>
<pre><code class="language-js">function solution(a, b) {
    var sum = 0;
    for(var i=0; i&lt;a.length; i++){
        sum += a[i]*b[i];
    }
    return sum;
}</code></pre>
<p>풀이</p>
<ol>
<li>sum에다 더한 값을 바로 할당하며 배열들의 인덱스 엘리먼트를 곱한 값을 재할당 하면 reduce를 사용하지 않아도 더한 값을 반환할 수가 있었다.</li>
</ol>
<p>즉, 굳이 함수를 더 적용할 필요가 없었다.</p>
<p>#2</p>
<pre><code class="language-js">function solution(a, b) {
    return a.reduce((acc, _, i) =&gt; acc += a[i] * b[i], 0);
}</code></pre>
<p>풀이</p>
<ol>
<li>reduce만 사용한다면 위와 같이 cur(현재 값)을 제외하고 i(인덱스) 만 순회하여 더한 값을 반환할 수 있었을 것이다.</li>
</ol>
<pre><code class="language-js">function solution(a, b) {
  var answer = a.reduce((a, _, i) =&gt; (a += a[i] * b[i]), 0);
  return answer;
}</code></pre>
<p><strong>문제점</strong>
위의 함수를 기능하면 NaN이 나오게 되는데 왜그런지 이해할 수가 없었어서 gpt에게 물어 보았다.
<img src= https://velog.velcdn.com/images/woo_7i/post/963f7c34-1607-4acc-bf9b-707f38cbfe23/image.png width = "70%"></p>
<ol>
<li>reduce의 인자로 선언된 변수 a의 값으로 먼저 초기 값 0이 할당 되었기 때문에
뒤에 연산되어야 하는 a[i]의 값이 존재하지 않아 undefined가 된 것.</li>
</ol>
<p><strong>전달 되어야 하는 변수는 덮어씌어지지 않게 이름을 잘 작성해야 할 것.</strong></p>
]]></description>
        </item>
        <item>
            <title><![CDATA[🟣 오늘의 문제 회고]]></title>
            <link>https://velog.io/@woo_7i/%EC%98%A4%EB%8A%98%EC%9D%98-%EB%AC%B8%EC%A0%9C-%ED%9A%8C%EA%B3%A0-elw8tm5x</link>
            <guid>https://velog.io/@woo_7i/%EC%98%A4%EB%8A%98%EC%9D%98-%EB%AC%B8%EC%A0%9C-%ED%9A%8C%EA%B3%A0-elw8tm5x</guid>
            <pubDate>Sat, 25 Mar 2023 09:08:18 GMT</pubDate>
            <description><![CDATA[<h3 id="😚-오늘의-문제-핥짝-1">😚 오늘의 문제 핥짝 #1</h3>
<hr>
<blockquote>
<p><strong>[프로그래머스]</strong> Lv1: 음양 더하기</p>
</blockquote>
<p><strong>문제 설명</strong> 
어떤 정수들이 있습니다. 이 정수들의 절댓값을 차례대로 담은 정수 배열 absolutes와 이 정수들의 부호를 차례대로 담은 불리언 배열 signs가 매개변수로 주어집니다. 실제 정수들의 합을 구하여 return 하도록 solution 함수를 완성해주세요.</p>
<p><strong>제한사항</strong></p>
<ul>
<li>absolutes의 길이는 1 이상 1,000 이하입니다.<ul>
<li>absolutes의 모든 수는 각각 1 이상 1,000 이하입니다.</li>
</ul>
</li>
<li>signs의 길이는 absolutes의 길이와 같습니다.<ul>
<li>signs[i] 가 참이면 absolutes[i] 의 실제 정수가 양수임을, 그렇지 않으면 음수임을 의미합니다.</li>
</ul>
</li>
</ul>
<p><strong>입출력 예</strong></p>
<table>
<thead>
<tr>
<th align="center">absolutes</th>
<th align="center">signs</th>
<th align="center">result</th>
</tr>
</thead>
<tbody><tr>
<td align="center">[4,7,12]</td>
<td align="center">[true,false,true]</td>
<td align="center">9</td>
</tr>
<tr>
<td align="center">[1,2,3]</td>
<td align="center">[false,false,true]</td>
<td align="center">0</td>
</tr>
</tbody></table>
<hr>
<h3 id="나의-풀이">나의 풀이</h3>
<pre><code class="language-js">function solution(absolutes, signs) {
  var answer = absolutes;
  //signs[i] 가 참이면 absolutes[i] 의 실제 정수가 양수임을, 그렇지 않으면 음수임을 의미합니다.
  for (let i = 0; i &lt; signs.length; i++) {
    if (signs[i] != true) absolutes[i] *= -1;
  }
  return answer.reduce((a, c) =&gt; a + c);
}</code></pre>
<p><strong>구현 접근</strong></p>
<ol>
<li>answer 에다 absolutes 배열을 초기화</li>
<li>for 반복을 통해 sign[i] false면 -1을 곱한 값을 재 할당</li>
<li>answer의 reduce 메소드로 모두 더한 값을 반환.</li>
</ol>
<p><strong>문제점</strong>
마지막 return으로 메서드를 적용하여 반환하는 습관을 고쳐보자.
모든 리턴 값이 메서드를 적용해서 반환된다는 보장이 없기 때문에,,</p>
<hr>
<h3 id="다른-사람-풀이">다른 사람 풀이</h3>
<p>#1</p>
<pre><code class="language-js">function solution(absolutes, signs) {

    return absolutes.reduce((acc, val, i) =&gt; acc + (val * (signs[i] ? 1 : -1)), 0);
}</code></pre>
<p>풀이</p>
<ol>
<li>reduce 메서드 함수 적용에 acc(누산값)+cur/val(현재값)을 곱해주는 연산 적용</li>
<li>연산에 sign[i]? 삼항 조건을 통해 truthy면 1을 곱하고 falsy면 -1을 곱하게 함.</li>
<li>초기 값 0을 적용하여 acc값의 배열로 계산되지 않게 적용.</li>
</ol>
<p><br>#2</p>
<pre><code class="language-js">function solution(absolutes, signs) {
    let answer = 0;
    for (let i = 0; i &lt; absolutes.length; i++) {
        signs[i] ? answer += absolutes[i] : answer -= absolutes[i]
    }
    return answer;
}</code></pre>
<p>풀이</p>
<ol>
<li>answer를 0으로 초기화</li>
<li>for 반복과 삼항연산자를 통해 signs[i] 
인덱스 값이 truthy면 answer에다 absolutes[i]를 더한 값을 재할당.
falsy면 absolutes[i] 뺀 값을 재할당.</li>
</ol>
<hr>
<h3 id="😚-오늘의-문제-핥짝-2">😚 오늘의 문제 핥짝 #2</h3>
<blockquote>
<p><strong>[프로그래머스]</strong> Lv1: 제일 작은 수 제거하기</p>
</blockquote>
<p><strong>문제 설명</strong> 
정수를 저장한 배열, arr 에서 가장 작은 수를 제거한 배열을 리턴하는 함수, solution을 완성해주세요. 단, 리턴하려는 배열이 빈 배열인 경우엔 배열에 -1을 채워 리턴하세요. 예를들어 arr이 [4,3,2,1]인 경우는 [4,3,2]를 리턴 하고, [10]면 [-1]을 리턴 합니다.</p>
<p><strong>제한사항</strong></p>
<ul>
<li>arr은 길이 1 이상인 배열입니다.</li>
<li>인덱스 i, j에 대해 i ≠ j이면 arr[i] ≠ arr[j] 입니다.</li>
</ul>
<p><strong>입출력 예</strong></p>
<table>
<thead>
<tr>
<th align="center">absolutes</th>
<th align="center">result</th>
</tr>
</thead>
<tbody><tr>
<td align="center">[4,3,2,1]</td>
<td align="center">[4,3,2]</td>
</tr>
<tr>
<td align="center">[10]</td>
<td align="center">[-1]</td>
</tr>
</tbody></table>
<hr>
<h3 id="나의-풀이-1">나의 풀이</h3>
<pre><code class="language-js">function solution(arr) {
  var answer = arr.sort((a, b) =&gt; b - a).slice(0, -1);
  if (answer.length &lt;= 1) answer.push(-1);
  return answer;
}</code></pre>
<p><strong>구현 접근</strong></p>
<ol>
<li>sort 메서드를 적용하여 최소 값이 제일 뒤로 올 수있게 정렬</li>
<li>slice 메서드를 이용하여 가장 마지막 인덱스 값을 추출한 뒤 추출된 배열 반환.</li>
<li>if 조건을 통해 answer의 길이가 1이하가 되면 -1을 배열로 반환.</li>
</ol>
<p><strong>문제점</strong>
이 과정에서 sort를 이용하게 되면 테스트 케이스를 통과하지 못 함.
그 이유를 찾아보니 반환 된 return이 정렬되어 나오는 것이 아닌 최소 값만 추출하여 배열 그대로 반환하는 요구사항이었다.</p>
<p>최소 값을 구할 수 있을 다른 방법이 무엇 있을까 고민하다 Math.min 메서드를 활용하여 함수를 구현하면 될 것 같았다.</p>
<br>

<p><strong>개선된 방법.</strong></p>
<pre><code class="language-js">function solution(arr) {
  var minValue = Math.min(...arr);
  var answer = arr.filter((e) =&gt; e !== minValue);
  if (answer.length === 0) answer.push(-1);
  return answer;
}</code></pre>
<p><strong>구현 접근</strong></p>
<ol>
<li>Math.min 메서드와 스프레드 문법을 통해 min 인자에 arr 배열을 전달.</li>
<li>filter 메서드를 통해 테스트를 통과한 배열 반환</li>
<li>if 조건에서 answer길이가 0이면 -1 배열에 할당하여 반환.</li>
</ol>
<hr>
<h3 id="다른-사람-풀이-1">다른 사람 풀이</h3>
<p>#1</p>
<pre><code class="language-js">function solution(arr) {
    arr.splice(arr.indexOf(Math.min(...arr)),1);
    if(arr.length&lt;1)return[-1];
    return arr;
}</code></pre>
<p>풀이
1.splice 메서드 안에 splice 메서드의 start 값으로 최고 값으로 속해있는 인덱스를 찾아 start를 기준했고, 삭제할 요소를 1로 한번에 설정해낸 것을 알 수 있었다.
2. 다음 if 조건을 통해 배열에 [-1]을 반환할 수 있도록 설정 하였다.</p>
<hr>
<h3 id="😚-오늘의-문제-핥짝-3">😚 오늘의 문제 핥짝 #3</h3>
<blockquote>
<p><strong>[프로그래머스]</strong> Lv1: 없는 숫자 더하기</p>
</blockquote>
<p><strong>문제 설명</strong> 
0부터 9까지의 숫자 중 일부가 들어있는 정수 배열 numbers가 매개변수로 주어집니다. numbers에서 찾을 수 없는 0부터 9까지의 숫자를 모두 찾아 더한 수를 return 하도록 solution 함수를 완성해주세요.</p>
<p><strong>제한사항</strong></p>
<ul>
<li>1 ≤ numbers의 길이 ≤ 9<ul>
<li>0 ≤ numbers의 모든 원소 ≤ 9</li>
<li>numbers의 모든 원소는 서로 다릅니다.    </li>
</ul>
</li>
</ul>
<p><strong>입출력 예</strong></p>
<table>
<thead>
<tr>
<th align="center">numbers</th>
<th align="center">result</th>
</tr>
</thead>
<tbody><tr>
<td align="center">[1,2,3,4,6,7,8,0]</td>
<td align="center">14</td>
</tr>
<tr>
<td align="center">[5,8,4,0,6,7,9]</td>
<td align="center">6</td>
</tr>
</tbody></table>
<hr>
<h3 id="나의-풀이-2">나의 풀이</h3>
<pre><code class="language-js">function solution(numbers) {
  var answer = [];
  var setArr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0];
  for (let i = 0; i &lt;= setArr.length; i++) {
    if (setArr.indexOf([i]) != numbers.indexOf([i])) answer.push(setArr[i]);
  }
  return answer;
</code></pre>
<p><strong>구현 접근</strong></p>
<ol>
<li>비교한 나머지 값을 담을 빈 배열 answer와 모든 배열을 가진 setArr를 선언</li>
<li>해당 배열을 순회하여 비교하는 배열과 순회하는 배열 속에서 존재하지 않는 값 추출하기 위해
처음엔 filter 메서드를 이용하여 접근하려 했는데 원하던 값이 나오지 않아 indexOf 메서드를 사용. 
그러나 두 함수에서 계속해서 인덱스를 비교한 값만 반환되어 요소를 비교하기 위해선 어떤 메서드가 필요한지 gpt에게 물어봤다,,</li>
</ol>
<p align = "center">
<img src = https://velog.velcdn.com/images/woo_7i/post/4b059409-9dee-46d5-8ac2-292500068242/image.png width ="70%">

<img src = https://velog.velcdn.com/images/woo_7i/post/a19bbe9b-1b84-4eba-acbe-13068a09750c/image.png width ="70%">
</p>

<p>gpt는 배열의 요소를 비교하기 위ㅣ해서는 includes( )메서드를 사용해야 한다고 했다.</p>
<blockquote>
<p>MDN에서도 includes() 메서드는 배열이 특정 요소를 포함하고 있는지 판별합니다.
라고 나와 있었다,, </p>
</blockquote>
<p>좀 더 찾아보고 문제를 해결 할 능력을 길러야 되겠다..</p>
<br>

<p><strong>하지만</strong> 이렇게만 끝내기엔 너무 아쉬워 기존에 적용하고 싶었던 filter 메소드를 이용하여 includes 메소드와 함께 적용하면 문제가 해결될 것 같아서 적용 해보았다.</p>
<br>

<p><strong>그렇게 개선하게 된 코드!</strong></p>
<pre><code class="language-js">function solution(numbers) {
  var setArr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0];
  var answer = setArr.filter((e, i) =&gt; !numbers.includes(setArr[i]));
  // filter의 e는 엘리먼트 이므로 number.includes에서 number 배열에 포함되지 않는 인덱스 위치 를 반환.
  return answer.reduce((a, c) =&gt; a + c);
}</code></pre>
<blockquote>
<p>filter() 메서드는 주어진 함수의 테스트를 통과하는 모든 요소를 모아 새로운 배열로 반환합니다.</p>
</blockquote>
<p><strong>적용 방식은</strong></p>
<pre><code class="language-js"> arr.filter(callback(element[, index[, array]])[, thisArg])
Copy to Clipboard</code></pre>
<p>첫 번째 인자로 배열의 element를 순회하여 돌고, 두 번째 인자로 index를 돌아서 값을 비교하는 구문이다.</p>
<pre><code class="language-js">function solution(numbers) {
  var setArr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0];
  var answer = setArr.filter((e) =&gt; !numbers.includes(setArr[e]));
  // filter의 e는 엘리먼트 이므로 number.includes에서 number 배열에 포함되지 않는 인덱스 위치 를 반환.  
  // [4, 8]
  return answer.reduce((a, c) =&gt; a + c);
}</code></pre>
<p>처음 filter를 적용하여 순회할 때 인자에 e값만 적용되어 반환된 값이 계속해서 [4,8]이길래 왜지 싶었는데, 해당 element가 속한 인덱스의 자리 값을 알려주는 것이었다.</p>
<p><strong>그렇게 개선된 코드에서는</strong></p>
<pre><code class="language-js">  var answer = setArr.filter((e,i) =&gt; !numbers.includes(setArr[i]));
// [5, 9]</code></pre>
<p>인덱스를 순회하여 해당 인덱스에 속해있는 element값을 반환하게 되니 
원하는 [5,9] 결과 값을 얻게 되었다.</p>
<hr>
<h3 id="다른-사람-풀이-2">다른 사람 풀이</h3>
<p>#1</p>
<pre><code class="language-js">function solution(numbers) {
    return 45 - numbers.reduce((cur, acc) =&gt; cur + acc, 0);
}</code></pre>
<p>풀이</p>
<ol>
<li>비교 대상인 전체 배열의 총합에서 비교해야 될 배열의 총합을 빼게되면 원하는 나머지 값을 얻게 되는 것이었다,, (천재인가..)</li>
</ol>
<p>#2</p>
<pre><code class="language-js">function solution(numbers) {
    let answer = 0;

    for(let i = 0; i &lt;= 9; i++) {
        if(!numbers.includes(i)) answer += i;
    }

    return answer;
}</code></pre>
<p>풀이</p>
<ol>
<li>gpt에서 알려준 것 처럼 대부분의 사람들은 
특정 요소 값을 비교하기 위해 includes( ) 메소드를 사용했던 것을 알 수 있었다.</li>
</ol>
]]></description>
        </item>
        <item>
            <title><![CDATA[🟣 오늘의 문제 회고]]></title>
            <link>https://velog.io/@woo_7i/%EC%98%A4%EB%8A%98%EC%9D%98-%EB%AC%B8%EC%A0%9C-%ED%9A%8C%EA%B3%A0-ak5ss5mx</link>
            <guid>https://velog.io/@woo_7i/%EC%98%A4%EB%8A%98%EC%9D%98-%EB%AC%B8%EC%A0%9C-%ED%9A%8C%EA%B3%A0-ak5ss5mx</guid>
            <pubDate>Thu, 23 Mar 2023 12:08:10 GMT</pubDate>
            <description><![CDATA[<h3 id="🫠-오늘의-문제-핥짝-1">🫠 오늘의 문제 핥짝 #1</h3>
<hr>
<blockquote>
<p><strong>[프로그래머스]</strong> Lv1: 서울에서 김서방 찾기</p>
</blockquote>
<p><strong>문제 설명</strong> 
String형 배열 seoul의 element중 &quot;Kim&quot;의 위치 x를 찾아, &quot;김서방은 x에 있다&quot;는 String을 반환하는 함수, solution을 완성하세요. seoul에 &quot;Kim&quot;은 오직 한 번만 나타나며 잘못된 값이 입력되는 경우는 없습니다.</p>
<p><strong>제한사항</strong></p>
<ul>
<li>seoul은 길이 1 이상, 1000 이하인 배열입니다.</li>
<li>seoul의 원소는 길이 1 이상, 20 이하인 문자열입니다.</li>
<li>&quot;Kim&quot;은 반드시 seoul 안에 포함되어 있습니다.</li>
</ul>
<p><strong>입출력 예</strong></p>
<table>
<thead>
<tr>
<th align="center">seoul</th>
<th align="center">return</th>
</tr>
</thead>
<tbody><tr>
<td align="center">[&quot;Jane&quot;, &quot;Kim&quot;]</td>
<td align="center">&quot;김서방은 1에 있다&quot;</td>
</tr>
</tbody></table>
<hr>
<h3 id="나의-풀이">나의 풀이</h3>
<pre><code class="language-js">function solution(seoul) {
  let answer = 0;
  for (let i = 0; i &lt; seoul.length; i++) {
    if (seoul[i] === &quot;Kim&quot;) answer = i;
  }
  return (answer = `김서방은 ${answer}에 있다`);
}</code></pre>
<p><strong>구현 접근</strong></p>
<ol>
<li>seoul에 값으로 String 배열 입력.</li>
<li>String 배열의 element로 &quot;Kim&quot;의 위치 찾기 위한 반복.</li>
<li>조건을 통해 Kim과 배열의 인덱스 위치 찾기.</li>
<li>answer에 인덱스를 재할당.</li>
</ol>
<hr>
<p><strong>다른 사람 풀이</strong></p>
<pre><code class="language-js">function findKim(seoul) {
    return &quot;김서방은 &quot; + seoul.indexOf(&#39;Kim&#39;) + &quot;에 있다&quot;;
}</code></pre>
<p>Array.indexOf( )메소드 : indexOf( ) 메서드는 배열에서 지정된 요소를 찾을 수 있는 첫 번째 인덱스를 반환하고 존재하지 않으면 -1을 반환합니다.</p>
<p>를 통해 코드를 한 줄로 개선할 수 있는 방법도 있었다.</p>
<hr>
<h3 id="🫠-오늘의-문제-핥짝-2">🫠 오늘의 문제 핥짝 #2</h3>
<blockquote>
<p><strong>[프로그래머스]</strong> Lv1: 나누어 떨어지는 숫자 배열</p>
</blockquote>
<p><strong>문제 설명</strong> 
array의 각 element 중 divisor로 나누어 떨어지는 값을 오름차순으로 정렬한 배열을 반환하는 함수, solution을 작성해주세요.
divisor로 나누어 떨어지는 element가 하나도 없다면 배열에 -1을 담아 반환하세요.</p>
<p><strong>제한사항</strong></p>
<ul>
<li>arr은 자연수를 담은 배열입니다.</li>
<li>정수 i, j에 대해 i ≠ j 이면 arr[i] ≠ arr[j] 입니다.</li>
<li>divisor는 자연수입니다.</li>
<li>array는 길이 1 이상인 배열입니다.</li>
</ul>
<p><strong>입출력 예</strong></p>
<table>
<thead>
<tr>
<th align="center">arr</th>
<th align="center">divisor</th>
<th align="center">return</th>
</tr>
</thead>
<tbody><tr>
<td align="center">[5, 9, 7, 10]</td>
<td align="center">5</td>
<td align="center">[5,10]</td>
</tr>
<tr>
<td align="center">[2, 36, 1, 3]</td>
<td align="center">1</td>
<td align="center">[1,2,3,36]</td>
</tr>
<tr>
<td align="center">[3,2,6]</td>
<td align="center">10</td>
<td align="center">[-1]</td>
</tr>
</tbody></table>
<hr>
<h3 id="나의-풀이-1">나의 풀이</h3>
<pre><code class="language-js">// array의 각 element 중 divisor로 나누어 떨어지는 값을 오름차순으로 정렬한 배열을 반환하는 함수,
// solution을 작성해주세요.
// divisor로 나누어 떨어지는 element가 하나도 없다면 배열에 -1을 담아 반환하세요.

function solution(arr, divisor) {
  var answer = arr.filter((e) =&gt; e % divisor === 0).sort((a, b) =&gt; a - b);
  if (answer.length === 0) answer = [-1];

  return answer;
}</code></pre>
<p><strong>구현 접근</strong></p>
<ol>
<li><p>array의 각 element 중 divisor로 나누어 떨어지는 값을 
= divisor로 나누어떨어지는 조건을 filter( )메소드를 이용하여 조건의 true가 되어 반환되는 배열 받아옴</p>
</li>
<li><p>오름차순으로 정렬한 배열을 반환하는 함수,
= sort( )를 이용하여 오름차순 정렬</p>
</li>
<li><p>divisor로 나누어 떨어지는 element가 하나도 없다면 배열에 -1을 담아 반환하세요.
= if( )조건에 반환되는 배열이 빈배열이면 [-1]을 반환 하도록 설정.</p>
</li>
</ol>
<p><br><strong>문제점</strong>
<img src = https://velog.velcdn.com/images/woo_7i/post/dffc9425-64e0-404e-86bc-ed16ca1b4d85/image.png width ="70%"></p>
<p>if의 조건으로 (빈배열이면)에 해당하는 부분이 </p>
<pre><code class="language-js">if(answer == []) answer = [-1]</code></pre>
<p>으로 설정하였는데 Javascript에서는 [ ] 배열 type이 object 설정되어 있기 때문에 원하는 반환 값이 나오지 않았었다.</p>
<pre><code class="language-js">if(answer.length == 0) answer = [-1]</code></pre>
<p>위와 같이 수정되어야 배열이 비어있는지 없는지 확인할 수 있는 조건이 완성 된다.</p>
<hr>
<h3 id="🫠-오늘의-문제-핥짝-3">🫠 오늘의 문제 핥짝 #3</h3>
<blockquote>
<p><strong>[프로그래머스]</strong> Lv1: 핸드폰 번호 가리기</p>
</blockquote>
<p><strong>문제 설명</strong> 
프로그래머스 모바일은 개인정보 보호를 위해 고지서를 보낼 때 고객들의 전화번호의 일부를 가립니다.
전화번호가 문자열 phone_number로 주어졌을 때, 전화번호의 뒷 4자리를 제외한 나머지 숫자를 전부 *으로 가린 문자열을 리턴하는 함수, solution을 완성해주세요.</p>
<p><strong>제한사항</strong></p>
<ul>
<li>phone_number는 길이 4 이상, 20이하인 문자열입니다.</li>
</ul>
<p><strong>입출력 예</strong></p>
<table>
<thead>
<tr>
<th align="center">phone_number</th>
<th align="center">return</th>
</tr>
</thead>
<tbody><tr>
<td align="center">&quot;01033334444&quot;</td>
<td align="center">&quot;* * * * * * * 4444&quot;</td>
</tr>
<tr>
<td align="center">&quot;027778888&quot;</td>
<td align="center">&quot;* * * * *8888&quot;</td>
</tr>
</tbody></table>
<hr>
<h3 id="나의-풀이-2">나의 풀이</h3>
<pre><code class="language-js">// 프로그래머스 모바일은 개인정보 보호를 위해 고지서를 보낼 때 고객들의 전화번호의 일부를 가립니다.
// 전화번호가 문자열 phone_number로 주어졌을 때,
// 전화번호의 뒷 4자리를 제외한 나머지 숫자를 전부 *으로 가린 문자열을 리턴하는 함수,
// solution을 완성해주세요.

function solution(phone_number) {
  var answer = phone_number.split(&quot;&quot;).fill(&quot;*&quot;, 0, -4);
  return answer.join(&quot;&quot;);
}</code></pre>
<p><strong>구현 접근</strong></p>
<ol>
<li>문자열로 입력되는 phone_number를 split(&#39;&#39;)를 이용하여 개별로 나뉘어진 배열로 반환</li>
<li>해당 배열을 fill(value,start, end) 메소드를 이용하여 넣고자 하는 value에 &#39;*&#39;를 입력하고 인덱스의 시작 값과 적용시켜야 할 인덱스까지 범위를 정해주었다.</li>
<li>문자열로 반환해야 하기 때문에 join( )메소드를 이용하여 문자열 반환.</li>
</ol>
<p>= 공식 MDN 문서의 표준내장 객체를 통해 꾸준히 학습하다 보니 &#39;뭔가 이런 종류의 메소드가 있었던 것 같은데,,,&#39;하면서 찾다보니 금방 금방 찾아서 적용 할 수 있게 되는 것 같다.</p>
<hr>
<h3 id="다른-사람-풀이">다른 사람 풀이</h3>
<p>#1</p>
<pre><code class="language-js">function hide_numbers(s){
  return s.replace(/\d(?=\d{4})/g, &quot;*&quot;);
}</code></pre>
<p>replace( ) 메서드는 어떤 패턴에 일치하는 일부 또는 모든 부분이 교체된 새로운 문자열을 반환합니다. 그 패턴은 문자열이나 정규식(RegExp)이 될 수 있으며, 교체 문자열은 문자열이나 모든 매치에 대해서 호출된 함수일 수 있습니다.</p>
<p>공식문서 MDN에 나와있기를, 정규식을 이용하여 string 타입의 메서드들 활용할 수 있는 범위가 넓어지는 것 같았다. 정규식 관련해서도 공부를 얼른 하고 적용해볼 수 있기를!!</p>
<p>#2</p>
<pre><code class="language-js">function hide_numbers(s){
    var result = &quot;*&quot;.repeat(s.length - 4) + s.slice(-4);
    return result;
  }</code></pre>
<p>String.prototype 관련하여 메소드를 적용시키신 분들도 계셨다. 훨씬 간단하게 적용 할 수 있을 것도 같다.</p>
<p>Array 메소드만 적용하려 하지말고 다양한 타입의 메소드를 적용할 수 있도록 해보자!</p>
]]></description>
        </item>
        <item>
            <title><![CDATA[🟣 오늘의 문제 회고]]></title>
            <link>https://velog.io/@woo_7i/%EC%98%A4%EB%8A%98%EC%9D%98-%EB%AC%B8%EC%A0%9C-%ED%9A%8C%EA%B3%A0-flngnx12</link>
            <guid>https://velog.io/@woo_7i/%EC%98%A4%EB%8A%98%EC%9D%98-%EB%AC%B8%EC%A0%9C-%ED%9A%8C%EA%B3%A0-flngnx12</guid>
            <pubDate>Tue, 21 Mar 2023 16:24:10 GMT</pubDate>
            <description><![CDATA[<h3 id="😭😭😭-오늘의-문제-핥짝-1">😭😭😭 오늘의 문제 핥짝 #1</h3>
<hr>
<blockquote>
<p><strong>[프로그래머스]</strong> Lv1: 콜라츠 추측</p>
</blockquote>
<p><strong>문제 설명</strong> 
1937년 Collatz란 사람에 의해 제기된 이 추측은, 주어진 수가 1이 될 때까지 다음 작업을 반복하면, 모든 수를 1로 만들 수 있다는 추측입니다. 작업은 다음과 같습니다.</p>
<blockquote>
<p>1-1. 입력된 수가 짝수라면 2로 나눕니다. 
1-2. 입력된 수가 홀수라면 3을 곱하고 1을 더합니다. 
2. 결과로 나온 수에 같은 작업을 1이 될 때까지 반복합니다. </p>
</blockquote>
<p>예를 들어, 주어진 수가 6이라면 6 → 3 → 10 → 5 → 16 → 8 → 4 → 2 → 1 이 되어 총 8번 만에 1이 됩니다. 위 작업을 몇 번이나 반복해야 하는지 반환하는 함수, solution을 완성해 주세요. 단, 주어진 수가 1인 경우에는 0을, 작업을 500번 반복할 때까지 1이 되지 않는다면 –1을 반환해 주세요.</p>
<p><strong>제한사항</strong>
입력된 수, num은 1 이상 8,000,000 미만인 정수입니다.</p>
<p><strong>입출력 예</strong></p>
<table>
<thead>
<tr>
<th align="center">n</th>
<th align="center">result</th>
</tr>
</thead>
<tbody><tr>
<td align="center">6</td>
<td align="center">8</td>
</tr>
<tr>
<td align="center">16</td>
<td align="center">4</td>
</tr>
<tr>
<td align="center">626331</td>
<td align="center">-1</td>
</tr>
</tbody></table>
<hr>
<h3 id="나의-풀이">나의 풀이</h3>
<pre><code class="language-js">function soliution(num) {
  // 단, 주어진 수가 1인 경우에는 0을,
  if (num === 1) return 0;
  // 몇번이나 반복해야 하는지 반환하는 함수, solution을 완성
    let answer = 0;
  //입력된 수가 짝수라면 2로 나눕니다. : 입력된 수가 홀수라면 3을 곱하고 1을 더합니다.
    let collatzNum = num % 2 === 0? num/2 :num*3+1; 

  //  결과로 나온 수에 같은 작업을 1이 될 때까지 반복합니다.
  while( ){

  }
}</code></pre>
<p><strong>문제점</strong>
<strong>반복을 해야할 풀이 코드를 변수에 할당 해버리고 어떻게 해야할지 감을 잡지 못 함.</strong>
answer에 할당한 코드를 반복하려면 기능을 해야하니 함수로 적용해야하는 건가..?
어떻게 반복문을 통해 
저 answer에 들어간 코드를 적용할지 그 이상의 진도를 나가지 못 해,,,
결국 풀이를 살펴보았다.</p>
<hr>
<p><strong>다른 사람 풀이</strong>
#1</p>
<pre><code class="language-js">function solution(num) {
      var answer = 0;
    while(num !=1 &amp;&amp; answer !=500){
        num%2==0 ? num = num/2 : num = num*3 +1;
    answer++;
  }
    return num == 1 ? answer : -1;
}
</code></pre>
<p>유감스럽게도 풀이에 내가 원하고자 했던 풀이를 그대로 풀어주신 개발자가 계셨다..!</p>
<p><strong>구현 접근 법</strong></p>
<ol>
<li><p>몇번이나 반복해야 하는지 반환하는 함수, solution을 완성 
변수 answer = 0</p>
</li>
<li><p>결과로 나온 수에 같은 작업을 1이 될 때까지 반복합니다.
입력된 수가 짝수라면 2로 나눕니다. : 입력된 수가 홀수라면 3을 곱하고 1을 더합니다.</p>
<ul>
<li>while의 반복 조건과 while 블록의 num이 조건에 맞아 떨어질 때까지 반복을 하는 코드 구현. 
(num != 1) num이 1이 아니면 계속 반복.
블록의 num에 값을 반복 할당, answer 값을 더해줌.</li>
</ul>
</li>
</ol>
<ol start="3">
<li>단, 주어진 수가 1인 경우에는 0을 
제한 조건까지 코드 구현완료 한 정말 내가 그대로 구현하고 싶던 함수 그 자체였다..!</li>
</ol>
<img src = https://velog.velcdn.com/images/woo_7i/post/a69d0181-2504-42be-8471-0f5add6f6465/image.png width ="70%">
gpt에 내 코드를 개선 해달라고 요청했을 때 받은 답변이다. 여기서 참고할 수 있었던 건
위 풀이에서 while 블록의 num을 삼항 조건마다 할당하는 방식을 
<br>gpt의 답변에서는 num 자체에다 조건 연산자를 할당하는 것이 리팩터링 될 수 있는 코드이지 않을까 생각했다.

<pre><code class="language-js"> while(num !=1 &amp;&amp; answer !=500){
        num%2==0 ? num = num/2 : num = num*3 +1;
    answer++;
  }

// 이와 같이 수정이 될 수 있을 것 같다.
while(num !=1 &amp;&amp; answer !=500){
        num = num%2==0 ? num/2 : num*3 +1;
    answer++;
  }</code></pre>
<p><br>#2</p>
<pre><code class="language-js">function collatz(num, count = 0) {
    return (num == 1) ? ((count &gt;= 500) ? -1 : count) : collatz((num % 2 == 0) ? num / 2 : (num * 3) + 1, ++count);
}</code></pre>
<p><strong>구현 접근 법</strong></p>
<ol>
<li>매개변수 자체에 두번째 인자로 리턴할 최종 값을 선언 하고.</li>
<li>조건연산자와 재귀를 통해 해당 함수를 반복하여 리턴 값을 구하는 것이 인상 깊었다.</li>
</ol>
<hr>
<h3 id="🧐-오늘의-학습">🧐 오늘의 학습</h3>
<p>변수에 할당한 값을 반복해서 원한는 값을 얻을려면 함수를 통해 재 호출해서 기능을 해내는 것도 가능하지만(= 재귀), 
반복문 내에 적용하려는 변수 표현식을 적용하여 얻고자 하는 값을 재할당이 가능하다.</p>
<p>즉, 반복문 자체도 기능인셈..!</p>
]]></description>
        </item>
    </channel>
</rss>