<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
    <channel>
        <title>jooyong-boo.log</title>
        <link>https://velog.io/</link>
        <description></description>
        <lastBuildDate>Fri, 30 Aug 2024 16:58:28 GMT</lastBuildDate>
        <docs>https://validator.w3.org/feed/docs/rss2.html</docs>
        <generator>https://github.com/jpmonette/feed</generator>
        <image>
            <title>jooyong-boo.log</title>
            <url>https://velog.velcdn.com/images/jooyong-boo/profile/c0e42b50-bef6-49d2-a3da-5270a22d5c8a/social_profile.png</url>
            <link>https://velog.io/</link>
        </image>
        <copyright>Copyright (C) 2019. jooyong-boo.log. All rights reserved.</copyright>
        <atom:link href="https://v2.velog.io/rss/jooyong-boo" rel="self" type="application/rss+xml"/>
        <item>
            <title><![CDATA[nextjs appRouter middleware 작동 안할때]]></title>
            <link>https://velog.io/@jooyong-boo/nextjs-appRouter-middleware-%EC%9E%91%EB%8F%99-%EC%95%88%ED%95%A0%EB%95%8C</link>
            <guid>https://velog.io/@jooyong-boo/nextjs-appRouter-middleware-%EC%9E%91%EB%8F%99-%EC%95%88%ED%95%A0%EB%95%8C</guid>
            <pubDate>Fri, 30 Aug 2024 16:58:28 GMT</pubDate>
            <description><![CDATA[<p>기본적으로 프로젝트 루트 경로에 있어야하지만 만약 src 디렉토리를 사용중이라면 src 디렉토리내 최상위에 위치해줘야 한다</p>
]]></description>
        </item>
        <item>
            <title><![CDATA[[tailwind css] 테일윈드 속성 적용 안될때?]]></title>
            <link>https://velog.io/@jooyong-boo/tailwind-css-%ED%85%8C%EC%9D%BC%EC%9C%88%EB%93%9C-%EC%86%8D%EC%84%B1-%EC%A0%81%EC%9A%A9-%EC%95%88%EB%90%A0%EB%95%8C</link>
            <guid>https://velog.io/@jooyong-boo/tailwind-css-%ED%85%8C%EC%9D%BC%EC%9C%88%EB%93%9C-%EC%86%8D%EC%84%B1-%EC%A0%81%EC%9A%A9-%EC%95%88%EB%90%A0%EB%95%8C</guid>
            <pubDate>Thu, 08 Aug 2024 13:36:36 GMT</pubDate>
            <description><![CDATA[<p>tailwind.config.ts 설정에서 </p>
<pre><code class="language-typescript">const config: Config = {
  content: [
    &quot;./src/pages/**/*.{js,ts,jsx,tsx,mdx}&quot;,
    &quot;./src/components/**/*.{js,ts,jsx,tsx,mdx}&quot;,
    &quot;./src/app/**/*.{js,ts,jsx,tsx,mdx}&quot;,
    &quot;./src/layouts/**/*.{js,ts,jsx,tsx,mdx}&quot;,
  ],
  theme: {
    extend: {
      backgroundImage: {
        &quot;gradient-radial&quot;: &quot;radial-gradient(var(--tw-gradient-stops))&quot;,
        &quot;gradient-conic&quot;:
          &quot;conic-gradient(from 180deg at 50% 50%, var(--tw-gradient-stops))&quot;,
      },
    },
  },
  plugins: [],
};
export default config;</code></pre>
<p>content에 경로 추가해주면 된다.</p>
]]></description>
        </item>
        <item>
            <title><![CDATA[tailwindcss vscode에서 css 자동완성 및 추천 안될때]]></title>
            <link>https://velog.io/@jooyong-boo/tailwindcss-vscode%EC%97%90%EC%84%9C-css-%EC%9E%90%EB%8F%99%EC%99%84%EC%84%B1-%EB%B0%8F-%EC%B6%94%EC%B2%9C-%EC%95%88%EB%90%A0%EB%95%8C</link>
            <guid>https://velog.io/@jooyong-boo/tailwindcss-vscode%EC%97%90%EC%84%9C-css-%EC%9E%90%EB%8F%99%EC%99%84%EC%84%B1-%EB%B0%8F-%EC%B6%94%EC%B2%9C-%EC%95%88%EB%90%A0%EB%95%8C</guid>
            <pubDate>Thu, 04 Jul 2024 15:03:35 GMT</pubDate>
            <description><![CDATA[<p>프로젝트 루트경로에 .vscode 폴더를 만든 후 settings.json을 만든다</p>
<pre><code class="language-json">{
  &quot;files.associations&quot;: {
    &quot;*html&quot;: &quot;html&quot;,
    &quot;*.css&quot;: &quot;tailwindcss&quot;
  },
  &quot;editor.quickSuggestions&quot;: {
    &quot;strings&quot;: true
  }
}</code></pre>
<p>이렇게 입력해주고 저장하면 잘된다.</p>
]]></description>
        </item>
        <item>
            <title><![CDATA[react-datepicker input 너비가 영역을 넘을때]]></title>
            <link>https://velog.io/@jooyong-boo/react-datepicker-input-%EB%84%88%EB%B9%84%EA%B0%80-%EC%98%81%EC%97%AD%EC%9D%84-%EB%84%98%EC%9D%84%EB%95%8C</link>
            <guid>https://velog.io/@jooyong-boo/react-datepicker-input-%EB%84%88%EB%B9%84%EA%B0%80-%EC%98%81%EC%97%AD%EC%9D%84-%EB%84%98%EC%9D%84%EB%95%8C</guid>
            <pubDate>Wed, 13 Mar 2024 01:24:45 GMT</pubDate>
            <description><![CDATA[<pre><code>.react-datepicker-wrapper, .react-datepicker__input-container { display: block; }
.react-datepicker-wrapper .react-datepicker__input-container input { width: 100% }</code></pre><p>글로벌 css 설정에 추가</p>
]]></description>
        </item>
        <item>
            <title><![CDATA[[Next.js] Image]]></title>
            <link>https://velog.io/@jooyong-boo/Next.js-Image</link>
            <guid>https://velog.io/@jooyong-boo/Next.js-Image</guid>
            <pubDate>Thu, 04 May 2023 10:09:19 GMT</pubDate>
            <description><![CDATA[<p>next.js에서 이미지를 사용할때 next에서 지원하는 Image가 있다</p>
<pre><code class="language-javascript">import Image from &#39;next/image&#39;</code></pre>
<p>&#39;Image&#39;는 기본적인 최적화를 해주는데 기본적으로 4가지가 있다.</p>
<li/>향상된 성능: 최신 이미지 형식을 사용하여 각 장치에 대해 항상 올바른 크기의 이미지 제공
<li/>시각적 안정성: 누적 레이아웃 이동 자동 방지
<li/>더 빠른 페이지 로드: 이미지가 뷰포트에 들어갈 때만 로드
<li/>자산 유연성: 원격 서버에 저장된 이미지에 대해서도 온디맨드 이미지 크기 조정

<p><strong>로컬 이미지</strong>(jpg, png, webp...)를 사용하려면 해당 이미지의 경로로 import해오면 된다.</p>
<pre><code class="language-javascript">import profilePic from &#39;../assets/me.png&#39;
</code></pre>
<p>Next.js는 가져온 파일에 따라 이미지의 너비와 높이를 자동으로 결정하며 이 값은 이미지가 로드되는 동안 누적 레이아웃 이동을 방지하는데 사용된다.</p>
<pre><code class="language-javascript">import Image from &#39;next/image&#39;
import profilePic from &#39;../assets/me.png&#39;

function Home() {
  return (
    &lt;&gt;
      &lt;h1&gt;My Homepage&lt;/h1&gt;
      &lt;Image
        src={profilePic}
        alt=&quot;Picture of the author&quot;
      /&gt;
      &lt;p&gt;Welcome to my homepage!&lt;/p&gt;
    &lt;/&gt;
  )
}</code></pre>
<p><strong>원격이미지</strong>를 사용하려면 src 속성이 상대적이거나 절대적인 URL 문자열이어야 한다.
Next.js는 빌드 프로세스 중에 원격 파일에 액세스할 수 없으므로 너비, 높이 및 선택적 blurDataURL props를 수동으로 제공해야 한다.</p>
<pre><code class="language-javascript">import Image from &#39;next/image&#39;

export default function Home() {
  return (
    &lt;&gt;
      &lt;h1&gt;My Homepage&lt;/h1&gt;
      &lt;Image
        src=&quot;/me.png&quot;
        alt=&quot;Picture of the author&quot;
        width={500}
        height={500}
      /&gt;
      &lt;p&gt;Welcome to my homepage!&lt;/p&gt;
    &lt;/&gt;
  )
}</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[[Next.js] useRouter와 context]]></title>
            <link>https://velog.io/@jooyong-boo/Next.js-useRouter%EC%99%80-context</link>
            <guid>https://velog.io/@jooyong-boo/Next.js-useRouter%EC%99%80-context</guid>
            <pubDate>Tue, 02 May 2023 09:47:55 GMT</pubDate>
            <description><![CDATA[<p>컴포넌트 안에서는 useRouter를 사용하여 url의 값을 받아올 수 있다.
<img src="https://velog.velcdn.com/images/jooyong-boo/post/5f8a8b80-378f-4665-9a94-2a9def73f15a/image.png" alt=""></p>
<p>getStaticProps 함수 안에서는 
<img src="https://velog.velcdn.com/images/jooyong-boo/post/ad3bc50b-0665-402b-b511-70e8254765a6/image.png" alt="">
이처럼 context를 사용하여 값을 받아올 수 있다.</p>
<p>getStaticProps 함수는 컴포넌트 함수보다 먼저 실행되기 때문에 데이터의 사전 준비가 필요하거나 하는 상황에서는 getStaticProps의 context를 사용해서 처리하자</p>
]]></description>
        </item>
        <item>
            <title><![CDATA[StoryBook v7 이상에서 styled-components theme 적용하기]]></title>
            <link>https://velog.io/@jooyong-boo/StoryBook-v7-%EC%9D%B4%EC%83%81%EC%97%90%EC%84%9C-styled-components-theme-%EC%A0%81%EC%9A%A9%ED%95%98%EA%B8%B0</link>
            <guid>https://velog.io/@jooyong-boo/StoryBook-v7-%EC%9D%B4%EC%83%81%EC%97%90%EC%84%9C-styled-components-theme-%EC%A0%81%EC%9A%A9%ED%95%98%EA%B8%B0</guid>
            <pubDate>Mon, 17 Apr 2023 16:04:53 GMT</pubDate>
            <description><![CDATA[<p>스토리북 v7 이상에서 styled-components theme를 적용하려했는데 적용이 잘 안되는 문제가 있었다.
<img src="https://velog.velcdn.com/images/jooyong-boo/post/00f1edc2-4cfb-491d-8816-0ad406c27ca7/image.png" alt="">
<img src="https://velog.velcdn.com/images/jooyong-boo/post/7e28076b-bc64-4f54-9f2d-a686f234e030/image.png" alt=""></p>
<p>v7이 업데이트 된지 얼마 안되서 그런줄알고 자료를 찾아보았으나 해결을 하지 못했는데 천천히 되짚어보니 아주 간단한 부분에서 실수를 한것이었다.</p>
<p>그것은 바로 확장명이 기본적으로 <strong>ts</strong>로 되어있었는데 이것을 <strong>tsx</strong>로 바꿔주면 정상적으로 적용이 된다...
<strong>js</strong>라면 <strong>jsx</strong>로 변경해주면 된다.</p>
<p><img src="https://velog.velcdn.com/images/jooyong-boo/post/a6da15f3-0e21-415a-a63d-0da71dcc17bd/image.png" alt=""></p>
<p>그외 redux나 react-router-dom 적용하는것도<img src="https://velog.velcdn.com/images/jooyong-boo/post/af44afa9-ac1d-4fda-a297-64354796cd7d/image.png" alt=""></p>
<p>이런식으로 index 파일에 적용하는거와 동일하게 해주면 된다.</p>
]]></description>
        </item>
        <item>
            <title><![CDATA[[javascript] 프로그래머스 레벨2 뉴스 클러스터링]]></title>
            <link>https://velog.io/@jooyong-boo/javascript-%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%A8%B8%EC%8A%A4-%EB%A0%88%EB%B2%A82-%EB%89%B4%EC%8A%A4-%ED%81%B4%EB%9F%AC%EC%8A%A4%ED%84%B0%EB%A7%81</link>
            <guid>https://velog.io/@jooyong-boo/javascript-%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%A8%B8%EC%8A%A4-%EB%A0%88%EB%B2%A82-%EB%89%B4%EC%8A%A4-%ED%81%B4%EB%9F%AC%EC%8A%A4%ED%84%B0%EB%A7%81</guid>
            <pubDate>Wed, 08 Mar 2023 12:41:13 GMT</pubDate>
            <description><![CDATA[<p><a href="https://school.programmers.co.kr/learn/courses/30/lessons/17677">문제보기</a></p>
<pre><code class="language-javascript">function solution(str1, str2) {
    var answer = 0;
    str1 = texting(str1);
    str2 = texting(str2);

    let union = unionFn(str1, str2);
    let intersect = intersectFn(str1, str2);

    function unionFn(first, second) {
        let union = { ...first };
        let result = [];
        for (const key in second) {
            if (union[key]) {
                if (union[key] &lt; second[key]) {
                    union[key] = second[key];
                }
            } else {
                union = { ...union, [key]: second[key] };
            }
        }
        for (const key in union) {
            for (let i = 0; i &lt; union[key]; i++) {
                result.push(key);
            }
        }
        return result;
    }

    function intersectFn(first, second) {
        let intersect = {};
        let result = [];
        for (const key in second) {
            if (first[key]) {
                if (first[key] &gt; second[key]) {
                    intersect = { ...intersect, [key]: second[key] };
                } else {
                    intersect = { ...intersect, [key]: first[key] };
                }
            }
        }
        for (const key in intersect) {
            for (let i = 0; i &lt; intersect[key]; i++) {
                result.push(key);
            }
        }
        return result;
    }

    function texting(str) {
        let arr = [...str.toLowerCase()];
        let result = {};
        for (let i = 0; i &lt; arr.length; i++) {
            let left = arr[i];
            let right = arr[i + 1];
            regex = /[a-zA-Z]/;
            if (
                left &amp;&amp;
                right &amp;&amp;
                isNaN(left) &amp;&amp;
                isNaN(right) &amp;&amp;
                regex.test(left) &amp;&amp;
                regex.test(right)
            ) {
                let sum = left + right;
                result[sum]
                    ? result[sum]++
                    : (result = { ...result, [sum]: 1 });
            }
        }
        return result;
    }

    if (!union.length &amp;&amp; !intersect.length) {
        return 65536;
    } else {
        answer = Math.floor(Number((intersect.length / union.length) * 65536));
        return Number(answer);
    }
}
</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[[javascript] 프로그래머스 레벨2 압축]]></title>
            <link>https://velog.io/@jooyong-boo/javascript-%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%A8%B8%EC%8A%A4-%EB%A0%88%EB%B2%A82-%EC%95%95%EC%B6%95</link>
            <guid>https://velog.io/@jooyong-boo/javascript-%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%A8%B8%EC%8A%A4-%EB%A0%88%EB%B2%A82-%EC%95%95%EC%B6%95</guid>
            <pubDate>Wed, 08 Mar 2023 12:39:15 GMT</pubDate>
            <description><![CDATA[<p><a href="https://school.programmers.co.kr/learn/courses/30/lessons/17684">문제보기</a></p>
<pre><code class="language-javascript">
function solution(msg) {
    var answer = [];
    msg = msg.split(&#39;&#39;);
    let dic = {};
    let charCode = [];
    let idxNum = 27;
    for (let i = 65; i &lt;= 90; i++) {
        charCode.push(String.fromCharCode(i));
    }
    for (let i = 0; i &lt; charCode.length; i++) {
        dic[charCode[i]] = i + 1;
    }

    for (let i = 0; i &lt; msg.length; i++) {
        let w = msg[i];
        let wc = msg[i];
        let whileI = i + 1;

        if (msg[whileI]) {
            while (true) {
                wc += msg[whileI];
                whileI++;
                if (dic[wc]) {
                    w = wc;
                } else {
                    answer.push(dic[w]);
                    i += w.length - 1;
                    dic[wc] = idxNum;
                    idxNum += 1;
                    break;
                }
            }
        } else {
            if (dic[w]) {
                answer.push(dic[w]);
            }
        }
    }
    return answer;
}
</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[[javascript] 백준 2493번 탑]]></title>
            <link>https://velog.io/@jooyong-boo/javascript-%EB%B0%B1%EC%A4%80-2493%EB%B2%88-%ED%83%91</link>
            <guid>https://velog.io/@jooyong-boo/javascript-%EB%B0%B1%EC%A4%80-2493%EB%B2%88-%ED%83%91</guid>
            <pubDate>Sun, 05 Feb 2023 12:10:12 GMT</pubDate>
            <description><![CDATA[<p><a href="https://www.acmicpc.net/problem/2493">문제보기</a></p>
<pre><code class="language-javascript">const fs = require(&quot;fs&quot;);
const filePath = process.platform === &quot;linux&quot; ? &quot;/dev/stdin&quot; : &quot;./input.txt&quot;;
let input = fs.readFileSync(filePath).toString().trim().split(&quot;\n&quot;);

const N = Number(input[0]);
const towers = input[1].split(&quot; &quot;).map((value) =&gt; +value);

let result = [];
let stack = [];
for (let i = 0; i &lt; N; i++) {
    let current = towers[i]; // 현재 타워의 높이
    if (!stack.length) result.push(0); // 현재 타워 왼쪽에 아무것도 없으면 0을 push
    if (stack.length) {
        let nextStack = []; // 현재 타워 왼쪽에서 비교한 것들을 모아두는 스택
        while (stack.length) {
            let [value, idx] = stack.pop();
            if (value &gt;= current) {
                result.push(idx);
                nextStack.push([value, idx]);
                break;
            }
        }
        if (nextStack.length) { // 왼쪽에서 비교한 타워들이 있으면 stack에 다시 push 해주고 없으면 0을 push
            stack.push(...nextStack);
        } else {
            result.push(0);
        }
    }
    stack.push([current, i + 1]); // 반복문이 한번 돌때마다 현재 타워의 값과 인덱스도 push해준다
}

console.log(result.join(&quot; &quot;));
</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[[javascript] 백준 2170번 선 긋기]]></title>
            <link>https://velog.io/@jooyong-boo/javascript-%EB%B0%B1%EC%A4%80-2170%EB%B2%88-%EC%84%A0-%EA%B8%8B%EA%B8%B0</link>
            <guid>https://velog.io/@jooyong-boo/javascript-%EB%B0%B1%EC%A4%80-2170%EB%B2%88-%EC%84%A0-%EA%B8%8B%EA%B8%B0</guid>
            <pubDate>Sat, 04 Feb 2023 09:09:13 GMT</pubDate>
            <description><![CDATA[<p><a href="https://www.acmicpc.net/problem/2170">문제보기</a></p>
<pre><code class="language-javascript">const fs = require(&quot;fs&quot;);
const filePath = process.platform === &quot;linux&quot; ? &quot;/dev/stdin&quot; : &quot;./input.txt&quot;;
let input = fs.readFileSync(filePath).toString().trim().split(&quot;\n&quot;);

const N = Number(input.shift());
const line = input
    .map((item) =&gt; item.split(&quot; &quot;).map((value) =&gt; +value))
    .sort((a, b) =&gt; a[0] - b[0]); // x좌표를 기준으로 오름차순 정렬

let result = [line[0]]; // 제일 처음값을 기준으로 시작
let count = 0;
for (let i = 1; i &lt; N; i++) {
    let [x, y] = line[i];
    if (x &lt;= result[0][1] &amp;&amp; y &gt; result[0][1]) { // x보다 기준이 되는 좌표의 y가 크거나 같고 y가 기준이 되는 좌표의 y보다 크면 선이 이어지는 부분이다
        result[0][1] = y; // 기준좌표 y값을 갱신해준다.
    }
    if (x &gt; result[0][1]) { // x가 기준좌표 y보다 크면 새로운 선이 생긴다
        count += result[0][1] - result[0][0]; // count에 기준좌표 y - x의 값을 더해주고
        result[0] = [x, y]; // 기준좌표를 새로 갱신해준다
    }
}
count += result[0][1] - result[0][0]; // 반복문이 종료된 후 기준좌표의 값을 count에 더해준다

console.log(count);
</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[[javascript] 백준 1926번 그림]]></title>
            <link>https://velog.io/@jooyong-boo/javascript-%EB%B0%B1%EC%A4%80-1926%EB%B2%88-%EA%B7%B8%EB%A6%BC</link>
            <guid>https://velog.io/@jooyong-boo/javascript-%EB%B0%B1%EC%A4%80-1926%EB%B2%88-%EA%B7%B8%EB%A6%BC</guid>
            <pubDate>Wed, 25 Jan 2023 14:26:14 GMT</pubDate>
            <description><![CDATA[<p><a href="https://www.acmicpc.net/problem/1926">문제보기</a></p>
<pre><code class="language-javascript">const fs = require(&quot;fs&quot;);
const filePath = process.platform === &quot;linux&quot; ? &quot;/dev/stdin&quot; : &quot;./input.txt&quot;;
let input = fs
    .readFileSync(filePath)
    .toString()
    .trim()
    .split(&quot;\n&quot;)
    .map((item) =&gt; item.split(&quot; &quot;).map((value) =&gt; +value));

const [n, m] = input.shift();
const visited = Array.from({ length: n }, () =&gt;
    Array.from({ length: m }, () =&gt; false)
);
let direction = [
    [1, 0],
    [-1, 0],
    [0, 1],
    [0, -1],
];
let answer = 0; // 그림의 갯수
let result = [];
const BFS = (start) =&gt; {
    let queue = [start];
    let total = 0; // 그림의 넓이 카운트
    while (queue.length) {
        let [y, x] = queue.shift();
        if (visited[y][x]) continue;
        visited[y][x] = true;
        total++;
        for (let i = 0; i &lt; direction.length; i++) {
            let [dy, dx] = [y + direction[i][0], x + direction[i][1]];
            if (dy &lt; 0 || dx &lt; 0 || dy &gt;= n || dx &gt;= m) continue;
            if (visited[dy][dx]) continue;
            if (input[dy][dx] === 1) { // 상하좌우 인접한곳에 그림이 연결되있으면
                queue.push([dy, dx]);
            }
        }
    }
    if (total) { // 그림의 넓이가 계산되어 있다면
        answer++; // 그림의 갯수 +1
        result.push(total); // result에 그림의 넓이 push
    }
};

for (let i = 0; i &lt; n; i++) {
    for (let j = 0; j &lt; m; j++) {
        if (input[i][j] === 1 &amp;&amp; !visited[i][j]) { // 그림이 있는곳이고 방문한적이 없다면 BFS 실행
            BFS([i, j]);
        }
    }
}
if (!answer) return console.log(0 + &quot;\n&quot; + 0); // 그림의 갯수가 없으면 0 출력
console.log(answer + &quot;\n&quot; + Math.max(...result)); // 그림의 갯수와 넓이가 담긴 배열에서 제일 큰 값을 출력한다</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[[javascript] 백준 1325번 효율적인 해킹]]></title>
            <link>https://velog.io/@jooyong-boo/javascript-%EB%B0%B1%EC%A4%80-1325%EB%B2%88-%ED%9A%A8%EC%9C%A8%EC%A0%81%EC%9D%B8-%ED%95%B4%ED%82%B9-qux42o4r</link>
            <guid>https://velog.io/@jooyong-boo/javascript-%EB%B0%B1%EC%A4%80-1325%EB%B2%88-%ED%9A%A8%EC%9C%A8%EC%A0%81%EC%9D%B8-%ED%95%B4%ED%82%B9-qux42o4r</guid>
            <pubDate>Sun, 15 Jan 2023 17:56:32 GMT</pubDate>
            <description><![CDATA[<p><a href="https://www.acmicpc.net/problem/1325">문제보기</a></p>
<pre><code class="language-javascript">const fs = require(&quot;fs&quot;);
const filePath = process.platform === &quot;linux&quot; ? &quot;/dev/stdin&quot; : &quot;./input.txt&quot;;
let input = fs
    .readFileSync(filePath)
    .toString()
    .trim()
    .split(&quot;\n&quot;)
    .map((item) =&gt; item.split(&quot; &quot;).map((value) =&gt; +value));

const [N, M] = input[0];
const graph = Array.from({ length: N + 1 }, () =&gt; []);
let answer = [];

// 인접리스트 
for (let i = 1; i &lt;= M; i++) {
    let [a, b] = input[i];
    graph[b].push(a);
}

let max = 0; // 해킹할수 있는 컴퓨터의 최대 수
const DFS = (start) =&gt; {
    const stack = [start];
    const visited = Array.from({ length: N + 1 }, () =&gt; false);
    let count = 0; // 해킹 가능한 컴퓨터의 수 카운트
    let result = 0; // 해당 컴퓨터의 해킹 가능한 최대 수
    while (stack.length) {
        let cur = stack.pop();
        if (result &lt; count) result = count;
        visited[cur] = true;
        for (let i = 0; i &lt; graph[cur].length; i++) {
            let value = graph[cur][i];
            if (visited[value]) continue;
            visited[value] = true;
            count += 1;
            stack.push(value);
        }
    }
    if (max &lt; result) { // 현재 해킹할수 있는 컴퓨터의 최대 수보다 이번 컴퓨터의 해킹 가능한 최대 수가 크다면
        max = result;
        answer = []; // 초기화
        answer.push(start);
    } else if (max === result) {
        answer.push(start);
    }
};

for (let i = 1; i &lt;= N; i++) {
    DFS(i);
}

console.log(answer.join(&quot; &quot;));
</code></pre>
<p>시간초과와 메모리초과가 번갈아가면서 나와서 멘붕이 왔던 문제였다..
우선 N과 M을 헷갈려서 헤멘것도 있고
while문 안에서 stack에 start를 [start] 이렇게 넣어서 구조분해 할당 하는식으로 했었는데 
코드를 천천히 살펴보니 불필요한 부분이라서 배열을 제거했더니 시간초과였던 코드가 통과됬다..
이유는 찾아보고 추가해야겠다</p>
]]></description>
        </item>
        <item>
            <title><![CDATA[[javascript] 백준 1389번 케빈 베이컨의 6단계 법칙]]></title>
            <link>https://velog.io/@jooyong-boo/javascript-%EB%B0%B1%EC%A4%80-1389%EB%B2%88-%EC%BC%80%EB%B9%88-%EB%B2%A0%EC%9D%B4%EC%BB%A8%EC%9D%98-6%EB%8B%A8%EA%B3%84-%EB%B2%95%EC%B9%99</link>
            <guid>https://velog.io/@jooyong-boo/javascript-%EB%B0%B1%EC%A4%80-1389%EB%B2%88-%EC%BC%80%EB%B9%88-%EB%B2%A0%EC%9D%B4%EC%BB%A8%EC%9D%98-6%EB%8B%A8%EA%B3%84-%EB%B2%95%EC%B9%99</guid>
            <pubDate>Thu, 12 Jan 2023 05:07:06 GMT</pubDate>
            <description><![CDATA[<p><a href="https://www.acmicpc.net/problem/1389">문제보기</a></p>
<pre><code class="language-javascript">const fs = require(&quot;fs&quot;);
const filePath = process.platform === &quot;linux&quot; ? &quot;/dev/stdin&quot; : &quot;./input.txt&quot;;
let input = fs
    .readFileSync(filePath)
    .toString()
    .trim()
    .split(&quot;\n&quot;)
    .map((item) =&gt; item.split(&quot; &quot;).map((value) =&gt; +value));

const [N, M] = input.shift();
const graph = Array.from({ length: N + 1 }, () =&gt; []);
const result = [];

// 친구 관계를 그래프로 정리
for (let i = 0; i &lt; M; i++) {
    const [A, B] = input[i];
    graph[A].push(B);
    graph[B].push(A);
}

const BFS = (start, target) =&gt; {
    const queue = [[start, 0]];
    const visited = Array.from({ length: N + 1 }, () =&gt; false);
    while (queue.length) {
        let [cur, count] = queue.shift();
        let friend = graph[cur];
        if (visited[cur]) continue;
        visited[cur] = true;
        if (cur === target) return count;

      // 그래프에서 가져온 친구관계를 순회하며 queue에 추가
        for (let i = 0; i &lt; friend.length; i++) {
            let value = friend[i];
            if (visited[value]) continue;
            queue.push([value, count + 1]);
        }
    }
};

// 1번부터 순차적으로 친구관계를 확인해야하기에 반복문을 통해 BFS 실행
for (let i = 0; i &lt; N; i++) {
    let count = 0;
    for (let j = 1; j &lt;= N; j++) {
        count += BFS(i + 1, j); // 리턴된 값들을 count에 더해준다
    }
    result.push(count); 
}

let min = Math.min(...result); // 케빈 베이컨의 수가 가장 작은것을 찾는다
console.log(result.indexOf(min) + 1); // 배열에서 가장 작은 수의 맨앞 인덱스를 출력한다
</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[[javascript] 백준 2644번 촌수계산]]></title>
            <link>https://velog.io/@jooyong-boo/javascript-%EB%B0%B1%EC%A4%80-2644%EB%B2%88-%EC%B4%8C%EC%88%98%EA%B3%84%EC%82%B0</link>
            <guid>https://velog.io/@jooyong-boo/javascript-%EB%B0%B1%EC%A4%80-2644%EB%B2%88-%EC%B4%8C%EC%88%98%EA%B3%84%EC%82%B0</guid>
            <pubDate>Tue, 10 Jan 2023 15:42:43 GMT</pubDate>
            <description><![CDATA[<p><a href="https://www.acmicpc.net/problem/2644">문제보기</a></p>
<pre><code class="language-javascript">const fs = require(&quot;fs&quot;);
const filePath = process.platform === &quot;linux&quot; ? &quot;/dev/stdin&quot; : &quot;./input.txt&quot;;
let input = fs.readFileSync(filePath).toString().trim().split(&quot;\n&quot;);

const n = Number(input.shift());
const [x, y] = input
    .shift()
    .split(&quot; &quot;)
    .map((value) =&gt; +value);
const m = Number(input.shift());

const data = input.map((item) =&gt; item.split(&quot; &quot;).map((v) =&gt; +v));
const graph = Array.from({ length: n + 1 }).map(() =&gt; []);
const visited = Array.from({ length: n + 1 }).map(() =&gt; false);

// 1촌 관계를 그래프로 정리
for (let i = 0; i &lt; data.length; i++) {
    const [x, y] = data[i];
    graph[x].push(y);
    graph[y].push(x);
}

// 사람수가 1이면 촌수 계산이 불가능하기에 -1 출력
if (n === 1) return console.log(-1);

const BFS = (start) =&gt; {
    const queue = [[start, 0]];

    while (queue.length) {
        let [qx, count] = queue.shift();
        let nearQx = graph[qx]; // 1촌 관계 그래프 가져오기
        if (visited[qx]) continue; // 방문체크
        if (qx === y) return count;
        visited[qx] = true;

       // 1촌 관계 반복문으로 순회
        for (let i = 0; i &lt; nearQx.length; i++) {
            let value = nearQx[i];
            if (visited[value]) continue; // 방문체크
            if (value === y) return count + 1; // y값과 일치하면 +1 해서 출력
            queue.push([value, count + 1]);
        }
    }
    return -1;
};

console.log(BFS(x));
</code></pre>
<p>문제풀이 
queue에 배열로 [값, 촌수] 를 넣어주는게 핵심이었다.</p>
]]></description>
        </item>
        <item>
            <title><![CDATA[[javascript] 백준 2206번 벽 부수고 이동하기]]></title>
            <link>https://velog.io/@jooyong-boo/javascript-%EB%B0%B1%EC%A4%80-2206%EB%B2%88-%EB%B2%BD-%EB%B6%80%EC%88%98%EA%B3%A0-%EC%9D%B4%EB%8F%99%ED%95%98%EA%B8%B0</link>
            <guid>https://velog.io/@jooyong-boo/javascript-%EB%B0%B1%EC%A4%80-2206%EB%B2%88-%EB%B2%BD-%EB%B6%80%EC%88%98%EA%B3%A0-%EC%9D%B4%EB%8F%99%ED%95%98%EA%B8%B0</guid>
            <pubDate>Sun, 08 Jan 2023 14:09:35 GMT</pubDate>
            <description><![CDATA[<p><a href="https://www.acmicpc.net/problem/2206">문제보기</a></p>
<pre><code class="language-javascript">const fs = require(&quot;fs&quot;);
const filePath = process.platform === &quot;linux&quot; ? &quot;/dev/stdin&quot; : &quot;./input.txt&quot;;
let input = fs.readFileSync(filePath).toString().trim().split(&quot;\n&quot;);

const [N, M] = input
    .shift()
    .split(&quot; &quot;)
    .map((value) =&gt; +value);

const map = input.map((item) =&gt; item.split(&quot;&quot;).map((value) =&gt; +value));

// 방문체크 배열 3차원 배열로 (벽을 부수지 않은 경우, 벽을 부순 경우) 2개로 나눈다.
const visited = Array.from({ length: 2 }, () =&gt;
    Array.from({ length: N }, () =&gt; Array.from({ length: M }).fill(false))
);

const direction = [
    [1, 0],
    [-1, 0],
    [0, 1],
    [0, -1],
];

if (N === 1 &amp;&amp; M === 1) return console.log(1);

const BFS = (start) =&gt; {
    let queue = [[...start, false, 1, 0]]; // 순서대로(시작지점, 벽을 부쉈는지 여부, 이동횟수, 방문체크 배열 z축 위치)
    let i = 0;
    while (queue.length &gt; i) {
        let [y, x, destroy, count, z] = queue[i];
        i++;
        visited[z][y][x] = true;
        if (y === N - 1 &amp;&amp; x === M - 1) return count;
        for (let i = 0; i &lt; direction.length; i++) {
            const [dy, dx] = [y + direction[i][0], x + direction[i][1]];
            if (dy &lt; 0 || dx &lt; 0 || dy &gt;= N || dx &gt;= M || visited[z][dy][dx])
                continue;
            if (dy === N - 1 &amp;&amp; dx === M - 1) return count + 1;
            if (destroy) { // 벽을 부순 경우에는
                if (map[dy][dx] === 1) continue;
              // 방문체크 z축을 이동하여 탐색한다
                queue.push([dy, dx, true, count + 1, 1]);
            } else {
                if (map[dy][dx] === 0)
                    queue.push([dy, dx, false, count + 1, 0]);
              // 다음에 벽을 부수게 된다면
                if (map[dy][dx] === 1) queue.push([dy, dx, true, count + 1, 1]);  // 방문체크 z축을 이동하여 탐색한다
            }
            visited[z][dy][dx] = true;
        }
    }
  // queue를 다 탐색했는데 목적지에 도달하지 못한다면 -1 출력
    return -1;
};

console.log(BFS([0, 0]));
</code></pre>
<p>풀이
이미 벽을 부순적이 있는 경우가 방문처리를 해버리는 바람에 부순적이 없는 경우가 접근해야 하는곳도 방문처리가 되어 결과를 제대로 도출할수가 없었다.
해결방법은 벽을 부순적이 있는지, 없는지에대해 방문여부를 3차원 배열로 만들어서
벽을 부수게 된다면 이후에는 z축으로 이동해서 진행하고 벽은 부순적이 없다면 계속 진행하면된다</p>
<p>queue 자료구조에 shift()를 사용하면 최대 100만개 크기인 이번 문제에서는 시간초과가 발생하기 떄문에 i라는 인덱스를 부여해서 while문이 1회 반복될때마다 i에 1을 더해주는 방식으로 queue를 순서대로 탐색하였다.</p>
]]></description>
        </item>
        <item>
            <title><![CDATA[[javascript] 백준 7569번 토마토]]></title>
            <link>https://velog.io/@jooyong-boo/javascript-%EB%B0%B1%EC%A4%80-7569%EB%B2%88-%ED%86%A0%EB%A7%88%ED%86%A0</link>
            <guid>https://velog.io/@jooyong-boo/javascript-%EB%B0%B1%EC%A4%80-7569%EB%B2%88-%ED%86%A0%EB%A7%88%ED%86%A0</guid>
            <pubDate>Thu, 05 Jan 2023 18:06:28 GMT</pubDate>
            <description><![CDATA[<p><a href="https://www.acmicpc.net/problem/7569">문제보기</a></p>
<pre><code class="language-javascript">const fs = require(&quot;fs&quot;);
const filePath = process.platform === &quot;linux&quot; ? &quot;/dev/stdin&quot; : &quot;./input.txt&quot;;
let input = fs
    .readFileSync(filePath)
    .toString()
    .trim()
    .split(&quot;\n&quot;)
    .map((item) =&gt; item.split(&quot; &quot;).map((value) =&gt; +value));

let [M, N, H] = input.shift();
let direction = [
    [-1, 0, 0],
    [1, 0, 0],
    [0, -1, 0],
    [0, 1, 0],
    [0, 0, 1],
    [0, 0, -1],
];

let box = [];

// 토마토 상자를 3차원 배열로 변환
for (let i = 0; i &lt; input.length; i++) {
    box.push(input.slice(i, N + i));
    i += N - 1;
}

// 방문여부 3차원 배열
let visited = Array.from({ length: H }, () =&gt;
    Array.from({ length: N }, () =&gt; Array.from({ length: M }).fill(false))
);

let tomato = []; // 익은 토마토의 위치
let unripe = 0; // 안익은 토마토의 갯수

for (let i = 0; i &lt; H; i++) {
    for (let j = 0; j &lt; N; j++) {
        for (let k = 0; k &lt; M; k++) {
            if (box[i][j][k] === 1) {
                tomato.push([k, j, i]);
            }
            if (box[i][j][k] === 0) {
                unripe++;
            }
        }
    }
}

// 안익은 토마토가 없으면 0을 반환
if (!unripe) return console.log(0);

const BFS = (tomato) =&gt; {
    let queue = [...tomato];
    let next = []; // 안익은 토마토의 위치
    let days = 0; // 날짜
    let i = 0;
    while (queue.length &gt; i) {
        let [x, y, h] = queue[i];
        i++;
        if (visited[h][y][x]) continue;
        visited[h][y][x] = true;
        box[h][y][x] = 1;
        for (let i = 0; i &lt; direction.length; i++) {
            let [dx, dy, dh] = [
                x + direction[i][0],
                y + direction[i][1],
                h + direction[i][2],
            ];
            if (
                dx &lt; 0 ||
                dy &lt; 0 ||
                dh &lt; 0 ||
                dx &gt;= M ||
                dy &gt;= N ||
                dh &gt;= H ||
                visited[dh][dy][dx] ||
                box[dh][dy][dx] === -1 ||
                box[dh][dy][dx] === 1
            ) {
                continue;
            }
            next.push([dx, dy, dh]);
            box[dh][dy][dx] = 1;
        }
        if (queue.length &lt;= i &amp;&amp; next.length) { // 현재 익은 토마토의 위치를 모두 확인했고 다음 안익은 토마토의 위치가 있으면
            days++;
            i = 0;
            queue = [];
            queue.push(...next);
            unripe -= next.length;
            next = [];
        }
    }
    if (unripe) return -1;

    return days;
};
console.log(BFS(tomato));
</code></pre>
<p>BFS로 풀이했다
처음에는 2차원 배열로도 충분히 푸는게 가능할것 같았으나 계속 시간초과 이슈가 생겨서 해결하지 못하고 3차원 배열로 풀이를 진행했다.
shift()를 이용하니까 시간초과가 발생해서 인덱스를 0부터 확인하는 방법으로 구현했더니 통과가 됬다.</p>
]]></description>
        </item>
        <item>
            <title><![CDATA[[javascript] 백준 10026번 적록색약]]></title>
            <link>https://velog.io/@jooyong-boo/javascript-%EB%B0%B1%EC%A4%80-10026%EB%B2%88-%EC%A0%81%EB%A1%9D%EC%83%89%EC%95%BD</link>
            <guid>https://velog.io/@jooyong-boo/javascript-%EB%B0%B1%EC%A4%80-10026%EB%B2%88-%EC%A0%81%EB%A1%9D%EC%83%89%EC%95%BD</guid>
            <pubDate>Wed, 04 Jan 2023 08:08:52 GMT</pubDate>
            <description><![CDATA[<p><a href="https://www.acmicpc.net/problem/10026">문제보기</a></p>
<pre><code class="language-javascript">const fs = require(&quot;fs&quot;);
const filePath = process.platform === &quot;linux&quot; ? &quot;/dev/stdin&quot; : &quot;./input.txt&quot;;
let input = fs.readFileSync(filePath).toString().trim().split(&quot;\n&quot;);

const N = Number(input.shift());
const map = input.map((item) =&gt; item.split(&quot;&quot;));
const direction = [
    [-1, 0],
    [1, 0],
    [0, -1],
    [0, 1],
];
const BFS = (start, map, N, weakness, visited, color) =&gt; { // 각 시작좌표, 맵, N, 색약여부, 방문여부, 시작좌표의 색
    let queue = [start];
    let count = 0;
    while (queue.length) {
        let [x, y] = queue.shift();
        if (visited[x][y]) continue;
        visited[x][y] = true;
        count++;
        for (let i = 0; i &lt; direction.length; i++) {
            let [dx, dy] = [x + direction[i][0], y + direction[i][1]];
            if (dx &lt; 0 || dy &lt; 0 || dx &gt;= N || dy &gt;= N) continue;
            if (visited[dx][dy]) continue;
            if (weakness) { // 색약일 경우
                if ( // R, G는 같은색으로 취급한다.
                    (color === &quot;R&quot; || color === &quot;G&quot;) &amp;&amp;
                    (map[dx][dy] === &quot;R&quot; || map[dx][dy] === &quot;G&quot;)
                ) {
                    queue.push([dx, dy]);
                }
                if (color === &quot;B&quot; &amp;&amp; map[dx][dy] === &quot;B&quot;) {
                    queue.push([dx, dy]);
                }
            } else { // 색약이 아니면 3개의 색을 구분한다
                if (color === &quot;R&quot; &amp;&amp; map[dx][dy] === &quot;R&quot;) {
                    queue.push([dx, dy]);
                }
                if (color === &quot;G&quot; &amp;&amp; map[dx][dy] === &quot;G&quot;) {
                    queue.push([dx, dy]);
                }
                if (color === &quot;B&quot; &amp;&amp; map[dx][dy] === &quot;B&quot;) {
                    queue.push([dx, dy]);
                }
            }
        }
    }
    return count;
};

let result = [0, 0];
for (let total = 0; total &lt; 2; total++) {
    let mode = [false, true]; // 색약여부 
    let count = 0;
    let visited = Array.from({ length: N }, () =&gt; Array(N).fill(false));
    for (let i = 0; i &lt; N; i++) {
        for (let j = 0; j &lt; N; j++) {
            if (visited[i][j]) continue;
            count = BFS([i, j], map, N, mode[total], visited, map[i][j]);
            if (count &gt; 0) result[total] += 1; // BFS에서 반환된 값이 0보다 크면 값을 1 올려준다
        }
    }
}

console.log(result.join(&quot; &quot;));</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[[javascript] 백준 2468번 안전 영역]]></title>
            <link>https://velog.io/@jooyong-boo/javascript-%EB%B0%B1%EC%A4%80-2468%EB%B2%88-%EC%95%88%EC%A0%84-%EC%98%81%EC%97%AD</link>
            <guid>https://velog.io/@jooyong-boo/javascript-%EB%B0%B1%EC%A4%80-2468%EB%B2%88-%EC%95%88%EC%A0%84-%EC%98%81%EC%97%AD</guid>
            <pubDate>Tue, 03 Jan 2023 12:35:33 GMT</pubDate>
            <description><![CDATA[<p><a href="https://www.acmicpc.net/problem/2468">문제보기</a></p>
<pre><code class="language-javascript">const fs = require(&quot;fs&quot;);
const filePath = process.platform === &quot;linux&quot; ? &quot;/dev/stdin&quot; : &quot;./input.txt&quot;;
let input = fs
    .readFileSync(filePath)
    .toString()
    .trim()
    .split(&quot;\n&quot;)
    .map((item) =&gt; item.split(&quot; &quot;).map((value) =&gt; +value));

const N = input.shift()[0];
const map = input.slice();
const visited = Array.from(Array(N + 1), () =&gt; Array(N).fill(false));
let direction = [
    [-1, 0],
    [0, 1],
    [1, 0],
    [0, -1],
];
let result = [];
let max = 0;

for (let i = 0; i &lt; N; i++) {
    for (let j = 0; j &lt; N; j++) {
        let info = map[i][j];
        if (max &lt; info) {
            max = info;
        }
    }
}

const DFS = (map, visited, safeList) =&gt; {
    let stack = [safeList];
    let count = 0;
    while (stack.length) {
        let [x, y] = stack.pop();
        if (!visited[x][y]) {
            visited[x][y] = true;
            count++;
        }
        for (let i = 0; i &lt; direction.length; i++) {
            let [dx, dy] = [x + direction[i][0], y + direction[i][1]];
            if (dx &lt; 0 || dy &lt; 0 || dx &gt;= N || dy &gt;= N) continue;
            if (!visited[dx][dy] &amp;&amp; map[dx][dy] &gt; 0) {
                count++;
                visited[dx][dy] = true;
                stack.push([dx, dy]);
            }
        }
    }

    return [count, map, visited];
};

//강수량이 0부터 최대높이까지 반복
for (let water = 0; water &lt;= max; water++) {
    // map과 visited를 복사한다
    let copyMap = map.map((item) =&gt; item.slice());
    let copyVisited = visited.map((item) =&gt; item.slice());
    let safeList = [];
    //강수량 이하인 지형들을 물에 잠기게한다
    for (let i = 0; i &lt; N; i++) {
        for (let j = 0; j &lt; N; j++) {
            if (copyMap[i][j] &lt;= water) {
                copyMap[i][j] = 0;
                copyVisited[i][j] = true;
            } else {
                safeList.push([i, j]);
            }
        }
    }
    let count = 0;
    for (let i = 0; i &lt; safeList.length; i++) {
        let [value, newMap, newVisited] = DFS(
            copyMap,
            copyVisited,
            safeList[i]
        );
        // 값이 있으면 증가
        if (value) {
            count++;
        }
        // 지도와 방문여부를 최신화해준다.
        copyMap = newMap;
        copyVisited = newVisited;
    }
    result.push(count);
    //DFS 실행해서 [0,0]부터 시작해서 잠기지않은 영역의 갯수를 카운트해서 결과에 넣는다
}

//결과중에서 제일 높은값을 출력한다.
console.log(Math.max(...result));
</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[[javascript] 백준 7562번 나이트의 이동]]></title>
            <link>https://velog.io/@jooyong-boo/javascript-%EB%B0%B1%EC%A4%80-7562%EB%B2%88-%EB%82%98%EC%9D%B4%ED%8A%B8%EC%9D%98-%EC%9D%B4%EB%8F%99</link>
            <guid>https://velog.io/@jooyong-boo/javascript-%EB%B0%B1%EC%A4%80-7562%EB%B2%88-%EB%82%98%EC%9D%B4%ED%8A%B8%EC%9D%98-%EC%9D%B4%EB%8F%99</guid>
            <pubDate>Mon, 02 Jan 2023 14:10:18 GMT</pubDate>
            <description><![CDATA[<p><a href="https://www.acmicpc.net/problem/7562">문제보기</a></p>
<pre><code class="language-javascript">const fs = require(&quot;fs&quot;);
const filePath = process.platform === &quot;linux&quot; ? &quot;/dev/stdin&quot; : &quot;./input.txt&quot;;
let input = fs
    .readFileSync(filePath)
    .toString()
    .trim()
    .split(&quot;\n&quot;)
    .map((item) =&gt; item.split(&quot; &quot;).map((value) =&gt; +value));

let map;
let direction = [
    [-1, 2],
    [-2, 1],
    [-2, -1],
    [-1, -2],
    [1, -2],
    [2, -1],
    [2, 1],
    [1, 2],
];

let num = input.shift()[0];
let result = [];

const BFS = (start, goal, L) =&gt; {
    let queue = [start];
    let [goalX, goalY] = goal;
    while (queue.length) {
        let [x, y] = queue.shift();
        if (map[y][x][1]) {
            continue;
        } else {
            map[y][x][1] = true;
        }
        for (let i = 0; i &lt; direction.length; i++) {
            let [dx, dy] = direction[i];
            if (x + dx &lt; 0 || y + dy &lt; 0 || x + dx &gt;= L || y + dy &gt;= L)
                continue;
            if (!map[y + dy][x + dx][1]) {
                map[y + dy][x + dx][0] = map[y][x][0] + 1;
                queue.push([x + dx, y + dy]);
                if (x + dx === goalX &amp;&amp; y + dy === goalY) {
                    return map[y + dy][x + dx][0];
                }
            }
        }
    }
};

for (let i = 0; i &lt; input.length; i++) {
    let testCase = input.slice(i, i + 3);
    i = i + 2;
    let L = testCase[0][0];
    let [startX, startY] = testCase[1];
    let [goalX, goalY] = testCase[2];
    map = [...Array(L)].map(() =&gt; [...Array(L)].map(() =&gt; [0, false]));

    if (startX === goalX &amp;&amp; startY === goalY) {
        result.push(0);
    } else {
        result.push(BFS([startX, startY], [goalX, goalY], L));
    }
}

console.log(result.join(&quot;\n&quot;));
</code></pre>
]]></description>
        </item>
    </channel>
</rss>