<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
    <channel>
        <title>dev-riverkim.log</title>
        <link>https://velog.io/</link>
        <description>dev-riverkim</description>
        <lastBuildDate>Wed, 13 Mar 2024 23:26:15 GMT</lastBuildDate>
        <docs>https://validator.w3.org/feed/docs/rss2.html</docs>
        <generator>https://github.com/jpmonette/feed</generator>
        <copyright>Copyright (C) 2019. dev-riverkim.log. All rights reserved.</copyright>
        <atom:link href="https://v2.velog.io/rss/dev-riverkim" rel="self" type="application/rss+xml"/>
        <item>
            <title><![CDATA[[알고리즘] 2024-02-29(목)]]></title>
            <link>https://velog.io/@dev-riverkim/%EC%95%8C%EA%B3%A0%EB%A6%AC%EC%A6%98-2024-02-29%EB%AA%A9</link>
            <guid>https://velog.io/@dev-riverkim/%EC%95%8C%EA%B3%A0%EB%A6%AC%EC%A6%98-2024-02-29%EB%AA%A9</guid>
            <pubDate>Wed, 13 Mar 2024 23:26:15 GMT</pubDate>
            <description><![CDATA[<h3 id="8-kyu---abbreviate-a-two-word-name">8 kyu - <strong>Abbreviate a Two Word Name</strong></h3>
<p>Write a function to convert a name into initials. This kata strictly takes two words with one space in between them.</p>
<p>The output should be two capital letters with a dot separating them.</p>
<p>It should look like this:</p>
<p><code>Sam Harris</code> =&gt; <code>S.H</code></p>
<p><code>patrick feeney</code> =&gt; <code>P.F</code></p>
<h3 id="solution">Solution</h3>
<pre><code class="language-jsx">function abbrevName(name){
  return name.split(&quot; &quot;).map(item =&gt;item[0].toUpperCase()).join(&#39;.&#39;)
}</code></pre>
<pre><code class="language-jsx">function abbrevName(name){

  var nameArray = name.split(&quot; &quot;);
  return (nameArray[0][0] + &quot;.&quot; + nameArray[1][0]).toUpperCase();
}</code></pre>
<pre><code class="language-jsx">function abbrevName(name){
  return name.split(&#39; &#39;).map(x =&gt; x.substr(0, 1).toUpperCase()).join(&#39;.&#39;);
}</code></pre>
<pre><code class="language-jsx">const abbrevName = name =&gt; name.match(/\b\w/g).join(&#39;.&#39;).toUpperCase()</code></pre>
<pre><code class="language-jsx">function abbrevName(name){
    return name[0].toUpperCase() + &quot;.&quot; + name[name.indexOf(&quot; &quot;)+1].toUpperCase();
}</code></pre>
<h3 id="8-kyu---convert-a-string-to-an-array">8 kyu - <strong>Convert a string to an array</strong></h3>
<p>Write a function to split a string and convert it into an array of words.</p>
<h3 id="examples-input--output">Examples (Input ==&gt; Output):</h3>
<pre><code>&quot;Robin Singh&quot; ==&gt; [&quot;Robin&quot;, &quot;Singh&quot;]

&quot;I love arrays they are my favorite&quot; ==&gt; [&quot;I&quot;, &quot;love&quot;, &quot;arrays&quot;, &quot;they&quot;, &quot;are&quot;, &quot;my&quot;, &quot;favorite&quot;]</code></pre><h3 id="solution-1">Solution</h3>
<pre><code class="language-jsx">function stringToArray(string){
      return string.split(&quot; &quot;);
}</code></pre>
<h3 id="8-kyu---find-the-smallest-integer-in-the-array">8 kyu - <strong>Find the smallest integer in the array</strong></h3>
<p>Given an array of integers your solution should find the smallest integer.</p>
<p>For example:</p>
<ul>
<li>Given <code>[34, 15, 88, 2]</code> your solution will return <code>2</code></li>
<li>Given <code>[34, -345, -1, 100]</code> your solution will return <code>345</code></li>
</ul>
<p>You can assume, for the purpose of this kata, that the supplied array will not be empty.</p>
<h3 id="solution-2">Solution</h3>
<pre><code class="language-jsx">class SmallestIntegerFinder {
  findSmallestInt(args) {
    return Math.min(...args)
  }
}</code></pre>
<pre><code class="language-jsx">class SmallestIntegerFinder {
  findSmallestInt(args) {
    return Math.min.apply(null, args);
  }
}</code></pre>
<pre><code class="language-jsx">class SmallestIntegerFinder {
  findSmallestInt(args) {
    return args.sort((a,b)=&gt;a-b)[0];
  }
}</code></pre>
<pre><code class="language-jsx">class SmallestIntegerFinder {
  findSmallestInt(args) {
    return args.reduce(function(prev, curr, index, array) {
      return prev &lt; curr ? prev : curr;
    });
  }
}</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[[알고리즘] 2024-02-28(수)]]></title>
            <link>https://velog.io/@dev-riverkim/%EC%95%8C%EA%B3%A0%EB%A6%AC%EC%A6%98-2024-02-28%EC%88%98</link>
            <guid>https://velog.io/@dev-riverkim/%EC%95%8C%EA%B3%A0%EB%A6%AC%EC%A6%98-2024-02-28%EC%88%98</guid>
            <pubDate>Wed, 13 Mar 2024 23:25:41 GMT</pubDate>
            <description><![CDATA[<h3 id="7-kyu---exes-and-ohs">7 kyu - Exes and Ohs</h3>
<p><a href="https://deeplify.dev/front-end/js/count-characters-in-string">https://deeplify.dev/front-end/js/count-characters-in-string</a></p>
<pre><code class="language-jsx">function XO(str) {
    // 문자열을 소문자로 변환
    str = str.toLowerCase();

    // &#39;x&#39;와 &#39;o&#39;의 개수를 저장할 변수 초기화
    let countX = 0;
    let countO = 0;

    // 문자열을 반복하며 &#39;x&#39;와 &#39;o&#39;의 개수 세기
    for (let char of str) {
        if (char === &#39;x&#39;) countX++;
        if (char === &#39;o&#39;) countO++;
    }

    // &#39;x&#39;와 &#39;o&#39;의 개수가 같으면 true, 다르면 false 반환
    return countX === countO;
}
</code></pre>
<pre><code class="language-jsx">function XO(str) {
    // 문자열을 소문자로 변환
    str = str.toLowerCase();

    // &#39;x&#39;와 &#39;o&#39;로 문자열을 분리하여 배열 생성
    const xCount = str.split(&#39;x&#39;).length - 1;
    const oCount = str.split(&#39;o&#39;).length - 1;

    // &#39;x&#39;와 &#39;o&#39;의 개수가 같은지 비교
    return xCount === oCount;
}</code></pre>
<pre><code class="language-jsx">function XO(str) {
    let xCount = 0;
    let oCount = 0;
    str = str.toLowerCase();

    for (let char of str) {
        if (char === &#39;x&#39;) xCount++;
        else if (char === &#39;o&#39;) oCount++;
    }

    return xCount === oCount;
}
</code></pre>
<pre><code class="language-jsx">function XO(str) {
    const xMatches = str.match(/x/gi);
    const oMatches = str.match(/o/gi);
    const xCount = xMatches ? xMatches.length : 0;
    const oCount = oMatches ? oMatches.length : 0;

    return xCount === oCount;
}</code></pre>
<h3 id="8-kyu---remove-first-and-last-character">8 kyu - <strong>Remove First and Last Character</strong></h3>
<p>It&#39;s pretty straightforward. Your goal is to create a function that removes the first and last characters of a string. You&#39;re given one parameter, the original string. You don&#39;t have to worry about strings with less than two characters.</p>
<h3 id="solution">Solution</h3>
<pre><code class="language-jsx">function removeChar(str){
 //You got this!
 // 매우 간단합니다. 문자열의 첫 번째 문자와 마지막 문자를 제거하는 함수를 만드는 것이 목표입니다. 
 // 하나의 매개변수, 즉 원본 문자열이 주어집니다. 두 글자 미만의 문자열은 걱정할 필요가 없습니다.

  return str.substring(1, str.length - 1)

};</code></pre>
<pre><code class="language-jsx">function removeChar(str) {
  return str.slice(1, -1);
}</code></pre>
<pre><code class="language-jsx">const removeChar = str =&gt; str.slice(1,-1)</code></pre>
<h3 id="8-kyu---is-it-even">8 kyu - Is it even?</h3>
<p>In this Kata we are passing a number (n) into a function.</p>
<p>Your code will determine if the number passed is even (or not).</p>
<p>The function needs to return either a true or false.</p>
<p>Numbers may be positive or negative, integers or floats.</p>
<p>Floats with decimal part non equal to zero are considered UNeven for this kata.</p>
<h3 id="solution-1">Solution</h3>
<pre><code class="language-jsx">function testEven(n) {
  return n%2 === 0 ? true : false
}</code></pre>
<pre><code class="language-jsx">function testEven(n) {
    return n%2===0;
}</code></pre>
<h3 id="7-kyu---categorize-new-member">7 kyu - Categorize New Member</h3>
<p>The Western Suburbs Croquet Club has two categories of membership, Senior 
and Open. They would like your help with an application form that will 
tell prospective members which category they will be placed.</p>
<p>To be a senior, a member must be at least 55 years old and have a 
handicap greater than 7. In this croquet club, handicaps range from -2 
to +26; the better the player the lower the handicap.</p>
<h2 id="input">Input</h2>
<p>Input will consist of a list of pairs. Each pair contains information
 for a single potential member. Information consists of an integer for 
the person&#39;s age and an integer for the person&#39;s handicap.</p>
<h2 id="output">Output</h2>
<p>Output will consist of a list of string values (in Haskell and C: <code>Open</code> or <code>Senior</code>) stating whether the respective member is to be placed in the senior or open category.</p>
<h3 id="example">Example</h3>
<pre><code>input =  [[18, 20], [45, 2], [61, 12], [37, 6], [21, 21], [78, 9]]
output = [&quot;Open&quot;, &quot;Open&quot;, &quot;Senior&quot;, &quot;Open&quot;, &quot;Open&quot;, &quot;Senior&quot;]</code></pre><h3 id="solution-2">Solution</h3>
<pre><code class="language-jsx">function openOrSenior(data){
  const result = data.map((item)=&gt;{
    return  item[0] &gt;= 55 &amp;&amp; item[1] &gt; 7 ? &quot;Senior&quot; : &quot;Open&quot;
  })
  return result;
}</code></pre>
<pre><code class="language-jsx">// Destructuring: [age, handicap] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment
// Arrow Functions: () =&gt; {} https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions

function openOrSenior(data){
  return data.map(([age, handicap]) =&gt; (age &gt; 54 &amp;&amp; handicap &gt; 7) ? &#39;Senior&#39; : &#39;Open&#39;);
}
</code></pre>
<pre><code class="language-jsx">function openOrSenior(data){
  function determineMembership(member){
    return (member[0] &gt;= 55 &amp;&amp; member[1] &gt; 7) ? &#39;Senior&#39; : &#39;Open&#39;;
  }
  return data.map(determineMembership);
}</code></pre>
<pre><code class="language-jsx">function openOrSenior(data){
  var result = [];
  data.forEach(function(member) {
    if(member[0] &gt;= 55 &amp;&amp; member[1] &gt; 7) {
      result.push(&#39;Senior&#39;);
    } else {
      result.push(&#39;Open&#39;);
    }
  })
  return result;
}</code></pre>
<pre><code class="language-jsx">function openOrSenior(data){
  return data.map(([age, handicap]) =&gt; age &gt;= 55 &amp;&amp; handicap &gt; 7 ? &#39;Senior&#39; : &#39;Open&#39;);
}</code></pre>
<pre><code class="language-jsx">function openOrSenior(data){
  return data.map(function(d){
    return d[0] &gt;= 55 &amp;&amp; d[1] &gt; 7 ? &#39;Senior&#39; : &#39;Open&#39;;
  });
}</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[[알고리즘] 2024-02-26(월)]]></title>
            <link>https://velog.io/@dev-riverkim/%EC%95%8C%EA%B3%A0%EB%A6%AC%EC%A6%98-2024-02-26%EC%9B%94</link>
            <guid>https://velog.io/@dev-riverkim/%EC%95%8C%EA%B3%A0%EB%A6%AC%EC%A6%98-2024-02-26%EC%9B%94</guid>
            <pubDate>Wed, 13 Mar 2024 23:24:56 GMT</pubDate>
            <description><![CDATA[<h3 id="7-kyu---testing-1-2-3">7 kyu - Testing 1-2-3</h3>
<p>Your team is writing a fancy new text editor and you&#39;ve been tasked with implementing the line numbering.</p>
<p>Write a function which takes a list of strings and returns each line prepended by the correct number.</p>
<p>The numbering starts at 1. The format is <code>n: string</code>. Notice the colon and space in between.</p>
<p><strong>Examples: (Input --&gt; Output)</strong></p>
<pre><code>[] --&gt; []
[&quot;a&quot;, &quot;b&quot;, &quot;c&quot;] --&gt; [&quot;1: a&quot;, &quot;2: b&quot;, &quot;3: c&quot;]</code></pre><h3 id="solution">Solution</h3>
<pre><code class="language-jsx">var number=function(array){
  //your awesome code here
  return array.map((item,index) =&gt; {
    return `${index+1}: ${item}`
  })

}</code></pre>
<pre><code class="language-jsx">var number = function(array) {
  return array.map(function (line, index) {
    return (index + 1) + &quot;: &quot; + line;
  });
}</code></pre>
<pre><code class="language-jsx">let number = (a) =&gt; a.map((v, i) =&gt; `${i + 1}: ${v}`)</code></pre>
<h3 id="8-kyu---area-or-perimeter">8 kyu - Area or Perimeter</h3>
<p>You are given the <code>length</code> and <code>width</code> of a 4-sided polygon. The polygon can either be a rectangle or a square.</p>
<p>If it is a square, return its area. If it is a rectangle, return its perimeter.</p>
<p><strong>Example(Input1, Input2 --&gt; Output):</strong></p>
<pre><code>6, 10 --&gt; 32
3, 3 --&gt; 9
</code></pre><p><strong>Note:</strong> for the purposes of this kata you will assume that it is a square if its <code>length</code> and <code>width</code> are equal, otherwise it is a rectangle.</p>
<h3 id="solution-1">Solution</h3>
<pre><code class="language-jsx">const areaOrPerimeter = function(l , w) {
  return l === w ? l * w : (l * 2) + (w * 2)
};</code></pre>
<pre><code class="language-jsx">const areaOrPerimeter = (l , w) =&gt; l === w ? l*w : 2*(l+w);</code></pre>
<pre><code class="language-jsx">const areaOrPerimeter = function(l , w) {
  let area = l * w;
  let perimeter = (l + w) * 2;

  return l === w ? area : perimeter;
};

// const areaOrPerimeter = (l, w) =&gt; l === w ? l * w : (l + w) * 2;</code></pre>
<h3 id="8-kyu---beginner---lost-without-a-map">8 kyu - Beginner - Lost Without a Map</h3>
<p>Given an array of integers, return a new array with each value doubled.</p>
<p>For example:</p>
<p><code>[1, 2, 3] --&gt; [2, 4, 6]</code></p>
<h3 id="solution-2">Solution</h3>
<pre><code class="language-jsx">function maps(x){ 
 return x.map((i) =&gt; {
    return i + i
  })
}</code></pre>
<pre><code class="language-jsx">function maps(x){
  return x.map(n =&gt; n * 2);
}</code></pre>
<pre><code class="language-jsx">maps = x =&gt; x.map(e =&gt; e * 2);</code></pre>
<h3 id="8-kyu---beginner-series-1-school-paperwork">8 kyu - Beginner Series #1 School Paperwork</h3>
<p>Your classmates asked you to copy some paperwork for them. You know that 
there are &#39;n&#39; classmates and the paperwork has &#39;m&#39; pages.</p>
<p>Your task is to calculate how many blank pages do you need. If <code>n &lt; 0</code> or <code>m &lt; 0</code> return <code>0</code>.</p>
<h3 id="example">Example:</h3>
<pre><code>n= 5, m=5: 25
n=-5, m=5:  0
</code></pre><p>Waiting for translations and Feedback! Thanks!</p>
<h3 id="solution-3">Solution</h3>
<pre><code class="language-jsx">function paperwork(n, m) {
  return n &lt; 0 || m &lt; 0 ? 0 : n * m
}</code></pre>
<pre><code class="language-jsx">function paperwork(n, m) {
  return n &gt; 0 &amp;&amp; m &gt; 0 ? n * m : 0
}</code></pre>
<pre><code class="language-jsx">function paperwork(n, m) {
  if (m &lt; 0 || n &lt; 0) {
    return 0;
  }
  return m * n;
}</code></pre>
<h3 id="7-kyu---anagram-detection">7 kyu - Anagram Detection</h3>
<p>An <strong>anagram</strong> is the result of rearranging the letters of a word to produce a new word (see <a href="https://en.wikipedia.org/wiki/Anagram">wikipedia</a>).</p>
<p><strong>Note:</strong> anagrams are case insensitive</p>
<p>Complete the function to return <code>true</code> if the two arguments given are anagrams of each other; return <code>false</code> otherwise.</p>
<h2 id="examples">Examples</h2>
<ul>
<li><code>&quot;foefet&quot;</code> is an anagram of <code>&quot;toffee&quot;</code></li>
<li><code>&quot;Buckethead&quot;</code> is an anagram of <code>&quot;DeathCubeK&quot;</code></li>
</ul>
<h3 id="solution-4">Solution</h3>
<pre><code class="language-jsx">// write the function isAnagram
var isAnagram = function(test, original) {

  // 애너그램은 단어의 글자를 재배열하여 새로운 단어를 만든 결과물입니다(위키백과 참조).
  // 참고: 애너그램은 대소문자를 구분하지 않습니다.

  // 주어진 두 인수가 서로의 애너그램이면 참을 반환하고, 그렇지 않으면 거짓을 반환하는 함수를 완성합니다.
  // 예제
  // &quot;foefet&quot;은 &quot;toffee&quot;의 아나그램입니다.
  // &quot;버킷헤드&quot;는 &quot;DeathCubeK&quot;의 아나그램입니다.

  // 두 문자열을 비교하여 문자가 몇 개 있는지 비교?

  test = test.toLowerCase()
  original = original.toLowerCase()

  // 문자열을 배열로 변환한 뒤 정렬하여 비교합니다.

  return test.split(&#39;&#39;).sort().join(&#39;&#39;) === original.split(&#39;&#39;).sort().join(&#39;&#39;);


};</code></pre>
<pre><code class="language-jsx">// write the function isAnagram
var isAnagram = function(test, original) {
  var t = test.toLowerCase().split(&#39;&#39;).sort().join(&#39;&#39;);
  var o = original.toLowerCase().split(&#39;&#39;).sort().join(&#39;&#39;);
  return (t==o)?true:false;
};</code></pre>
<pre><code class="language-jsx">function isAnagram (test, original) {
    return test.toLowerCase().split(&quot;&quot;).sort().join(&quot;&quot;) === original.toLowerCase().split(&quot;&quot;).sort().join(&quot;&quot;);
}</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[[알고리즘] 2024-02-23(금)]]></title>
            <link>https://velog.io/@dev-riverkim/%EC%95%8C%EA%B3%A0%EB%A6%AC%EC%A6%98-2024-02-23%EA%B8%88</link>
            <guid>https://velog.io/@dev-riverkim/%EC%95%8C%EA%B3%A0%EB%A6%AC%EC%A6%98-2024-02-23%EA%B8%88</guid>
            <pubDate>Wed, 13 Mar 2024 23:23:59 GMT</pubDate>
            <description><![CDATA[<h3 id="8-kyu---multiply">8 kyu - <strong>Multiply</strong></h3>
<p>This code does not execute properly. Try to figure out why.</p>
<h3 id="solution">Solution</h3>
<pre><code class="language-jsx">function multiply(a, b){
  return a * b
}</code></pre>
<h3 id="8-kyu---convert-a-number-to-a-string">8 kyu - <strong>Convert a Number to a String!</strong></h3>
<p>We need a function that can transform a number (integer) into a string.</p>
<p>What ways of achieving this do you know?</p>
<h3 id="examples-input----output">Examples (input --&gt; output):</h3>
<pre><code>123  --&gt; &quot;123&quot;
999  --&gt; &quot;999&quot;
-100 --&gt; &quot;-100&quot;</code></pre><h3 id="solution-1">Solution</h3>
<pre><code class="language-jsx">function numberToString(num) {
  return `${num}`
}</code></pre>
<pre><code class="language-jsx">function numberToString(num) {
  return num.toString();
}</code></pre>
<pre><code class="language-jsx">function numberToString(num) {
  // Return a string of the number here!
  return String(num);
}</code></pre>
<pre><code class="language-jsx">function numberToString(num) {
  return &#39;&#39;+num;
}</code></pre>
<h3 id="8-kyu---grasshopper---debug-sayhello">8 kyu - <strong>Grasshopper - Debug sayHello</strong></h3>
<h2 id="debugging-sayhello-function">Debugging sayHello function</h2>
<p>The starship Enterprise has run into some problem when creating a 
program to greet everyone as they come aboard. It is your job to fix the
 code and get the program working again!</p>
<p>Example output:</p>
<pre><code>Hello, Mr. Spock</code></pre><h3 id="solution-2">Solution</h3>
<pre><code class="language-jsx">function sayHello(name) {
  return `Hello, ${name}`
}</code></pre>
<pre><code class="language-jsx">const sayHello = name =&gt; `Hello, ${name}`;</code></pre>
<h3 id="7-kyu---is-this-a-triangle">7 kyu - <strong>Is this a triangle?</strong></h3>
<p>Implement a function that accepts 3 integer values a, b, c. The function should 
return true if a triangle can be built with the sides of given length 
and false in any other case.</p>
<p>(In this case, all triangles must have surface greater than 0 to be accepted).</p>
<p>Examples:</p>
<pre><code>Input -&gt; Output
1,2,2 -&gt; true
4,2,3 -&gt; true
2,2,2 -&gt; true
1,2,3 -&gt; false
-5,1,3 -&gt; false
0,2,3 -&gt; false
1,2,9 -&gt; false</code></pre><h3 id="solution-3">Solution</h3>
<pre><code class="language-jsx">function isTriangle(a,b,c)
{
  // 삼각형 성립조건
  // 가장 긴 변의 길이가 나머지 두 변의 길이의 합보다 작아야 함

  // 가장 큰 값을 구하고 나머지 두 값을 더해서 비교

  const arr = [a,b,c];

  let value = 0;

  arr.map((item) =&gt; {
    return item &gt; value ? value = item : value
  })


  return value +


}</code></pre>
<pre><code class="language-jsx">function isTriangle(a, b, c) {
  return (a + b &gt; c) &amp;&amp; (a + c &gt; b) &amp;&amp; (b + c &gt; a);
}</code></pre>
<pre><code class="language-jsx">function isTriangle(a, b, c) {
  let arr = [a, b, c].sort();
  return arr[2] &lt; (arr[0] + arr[1]);
}</code></pre>
<pre><code class="language-jsx">function isTriangle(a, b, c) {
  let max = Math.max(a, b, c);
  return max &lt; (a + b + c - max);
}</code></pre>
<pre><code class="language-jsx">function isTriangle(a, b, c) {
  let max = Math.max(a, b, c);
  return max &lt; (a + b + c) / 2;
}</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[[알고리즘] 2024-02-20(화)]]></title>
            <link>https://velog.io/@dev-riverkim/%EC%95%8C%EA%B3%A0%EB%A6%AC%EC%A6%98-2024-02-20%ED%99%94</link>
            <guid>https://velog.io/@dev-riverkim/%EC%95%8C%EA%B3%A0%EB%A6%AC%EC%A6%98-2024-02-20%ED%99%94</guid>
            <pubDate>Wed, 13 Mar 2024 23:23:04 GMT</pubDate>
            <description><![CDATA[<h3 id="8-kyu---remove-string-spaces">8 kyu - <strong>Remove String Spaces</strong></h3>
<p>Write a function that removes the spaces from the string, then return the resultant string.</p>
<p>Examples:</p>
<pre><code>Input -&gt; Output
&quot;8 j 8   mBliB8g  imjB8B8  jl  B&quot; -&gt; &quot;8j8mBliB8gimjB8B8jlB&quot;
&quot;8 8 Bi fk8h B 8 BB8B B B  B888 c hl8 BhB fd&quot; -&gt; &quot;88Bifk8hB8BB8BBBB888chl8BhBfd&quot;
&quot;8aaaaa dddd r     &quot; -&gt; &quot;8aaaaaddddr&quot;</code></pre><h3 id="solution">Solution</h3>
<pre><code class="language-jsx">function noSpace(x){
  return x.split(&quot; &quot;).join(&#39;&#39;)
}</code></pre>
<pre><code class="language-jsx">function noSpace(x){
  return x.replace(/\s/g, &#39;&#39;);
}</code></pre>
<pre><code class="language-jsx">function noSpace(x){return x.split(&#39; &#39;).join(&#39;&#39;)}</code></pre>
<h3 id="8-kyu---grasshopper---messi-goals-function">8 kyu - <strong>Grasshopper - Messi goals function</strong></h3>
<h1 id="messi-goals-function">Messi goals function</h1>
<p><a href="https://en.wikipedia.org/wiki/Lionel_Messi">Messi</a> is a soccer player with goals in three leagues:</p>
<ul>
<li>LaLiga</li>
<li>Copa del Rey</li>
<li>Champions</li>
</ul>
<p>Complete the function to return his total number of goals in all three leagues.</p>
<p>Note: the input will always be valid.</p>
<p>For example:</p>
<pre><code>5, 10, 2  --&gt;  17</code></pre><h3 id="solution-1">Solution</h3>
<pre><code class="language-jsx">function goals (laLigaGoals, copaDelReyGoals, championsLeagueGoals) {
  return laLigaGoals + copaDelReyGoals + championsLeagueGoals
}</code></pre>
<pre><code class="language-jsx">const goals = (...a) =&gt; a.reduce((s, v) =&gt; s + v, 0);</code></pre>
<pre><code class="language-jsx">const goals = (a,b,c) =&gt; a + b + c;</code></pre>
<h3 id="7-kyu---reverse-words">7 kyu - <strong>Reverse words</strong></h3>
<p>Complete the function that accepts a string parameter, and reverses each word in the string. <strong>All</strong> spaces in the string should be retained.</p>
<h2 id="examples">Examples</h2>
<pre><code>&quot;This is an example!&quot; ==&gt; &quot;sihT si na !elpmaxe&quot;
&quot;double  spaces&quot;      ==&gt; &quot;elbuod  secaps&quot;
</code></pre><h3 id="solution-2">Solution</h3>
<pre><code class="language-jsx">function reverseWords(str) {

  const words = str.split(&quot; &quot;);

  const newWord = words.map((item)=&gt;{
   return item.split(&quot;&quot;).reverse().join(&quot;&quot;)
  })

  return newWord.join(&quot; &quot;)


}</code></pre>
<pre><code class="language-jsx">function reverseWords(str) {
  return str.split(&#39; &#39;).map(function(word){
    return word.split(&#39;&#39;).reverse().join(&#39;&#39;);
  }).join(&#39; &#39;);
}</code></pre>
<pre><code class="language-jsx">function reverseWords(str) {
  // Go for it
  //split words into seperate arrays
  return str.split(&quot;&quot;).reverse().join(&quot;&quot;).split(&quot; &quot;).reverse().join(&quot; &quot;);
}</code></pre>
<pre><code class="language-jsx">function reverseWords(str) {
  return str.split(&#39; &#39;).map( str =&gt; str.split(&#39;&#39;).reverse().join(&#39;&#39;) ).join(&#39; &#39;);
}</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[[알고리즘] 2024-02-15(목)]]></title>
            <link>https://velog.io/@dev-riverkim/%EC%95%8C%EA%B3%A0%EB%A6%AC%EC%A6%98-2024-02-15%EB%AA%A9</link>
            <guid>https://velog.io/@dev-riverkim/%EC%95%8C%EA%B3%A0%EB%A6%AC%EC%A6%98-2024-02-15%EB%AA%A9</guid>
            <pubDate>Wed, 13 Mar 2024 23:22:09 GMT</pubDate>
            <description><![CDATA[<h2 id="8-kyu---5-without-numbers-">8 kyu - <strong>5 without numbers !!</strong></h2>
<p>Write a function that always returns <code>5</code></p>
<p>Sounds easy right? Just bear in mind that you can&#39;t use any of the following characters: <code>0123456789*+-/</code></p>
<p>Good luck :)</p>
<h3 id="solution">Solution</h3>
<pre><code class="language-jsx">function unusualFive() {
  return &#39;five!&#39;.length
}</code></pre>
<h2 id="8-kyu---invert-values">8 kyu - <strong>Invert values</strong></h2>
<p>Given a set of numbers, return the additive inverse of each. Each positive 
becomes negatives, and the negatives become positives.</p>
<pre><code>invert([1,2,3,4,5]) == [-1,-2,-3,-4,-5]
invert([1,-2,3,-4,5]) == [-1,2,-3,4,-5]
invert([]) == []
</code></pre><p>You can assume that all values are integers. Do not mutate the input array/list.</p>
<h3 id="solution-1">Solution</h3>
<pre><code class="language-jsx">function invert(array) {
  const result = array.map(item=&gt;{
    return item &gt; 0 ? -(item) : -(item)
  });
   return result ;
}</code></pre>
<pre><code class="language-jsx">const invert = array =&gt; array.map(num =&gt; -num);</code></pre>
<pre><code class="language-jsx">function invert(array) {
   return array.map( x =&gt; x === 0 ? x : -x);
}</code></pre>
<h2 id="8-kyu---counting-sheep">8 kyu - <strong>Counting sheep...</strong></h2>
<p>Consider an array/list of sheep where some sheep may be missing from their 
place. We need a function that counts the number of sheep present in the
 array (true means present).</p>
<p>For example,</p>
<pre><code class="language-jsx">[true,  true,  true,  false,
  true,  true,  true,  true ,
  true,  false, true,  false,
  true,  false, false, true ,
  true,  true,  true,  true ,
  false, false, true,  true]
</code></pre>
<p>The correct answer would be <code>17</code>.</p>
<p>Hint: Don&#39;t forget to check for bad values like <code>null</code>/<code>undefined</code></p>
<h3 id="solution-2">Solution</h3>
<pre><code class="language-jsx">function countSheeps(sheep) {
  let count = 0;

  sheep.map((index)=&gt;{
    return index === true ? count++ : false
  })  
  return count;
}</code></pre>
<pre><code class="language-jsx">function countSheeps(arrayOfSheeps) {
  return arrayOfSheeps.filter(Boolean).length;
}</code></pre>
<pre><code class="language-jsx">function countSheeps(arrayOfSheep) {
  var count = 0;

  arrayOfSheep.forEach( function (sheep) {
    if (sheep)
      count++;
  });

  return count;
}</code></pre>
<pre><code class="language-jsx">function countSheeps(arrayOfSheep) {
  // TODO May the force be with you
  var num = 0;

  for(var i = 0; i &lt; arrayOfSheep.length; i++)
    if(arrayOfSheep[i] == true)
      num++;

  return num;
}</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[[알고리즘] 2024-02-14(수)]]></title>
            <link>https://velog.io/@dev-riverkim/%EC%95%8C%EA%B3%A0%EB%A6%AC%EC%A6%98-2024-02-14%EC%88%98</link>
            <guid>https://velog.io/@dev-riverkim/%EC%95%8C%EA%B3%A0%EB%A6%AC%EC%A6%98-2024-02-14%EC%88%98</guid>
            <pubDate>Wed, 13 Mar 2024 23:21:32 GMT</pubDate>
            <description><![CDATA[<h2 id="8-kyu---remove-exclamation-marks">8 kyu - <strong>Remove exclamation marks</strong></h2>
<p>Write function RemoveExclamationMarks which removes all exclamation marks from a given string.</p>
<h3 id="solution">Solution</h3>
<pre><code class="language-jsx">function removeExclamationMarks(s) {
  // 주어진 문자열에서 모든 느낌표를 제거하는 함수 RemoveExclamationMarks를 작성합니다.

  return s.replaceAll(&#39;!&#39;,&#39;&#39;);;
}</code></pre>
<pre><code class="language-jsx">function removeExclamationMarks(s) {
  return s.replace(/!/gi, &#39;&#39;);
}</code></pre>
<pre><code class="language-jsx">function removeExclamationMarks(s) {
  return s.split(&#39;!&#39;).join(&#39;&#39;);
}</code></pre>
<h2 id="8-kyu---calculate-average">8 kyu - <strong>Calculate average</strong></h2>
<p>Write a function which calculates the average of the numbers in a given list.</p>
<p><strong>Note:</strong> Empty arrays should return 0.</p>
<h3 id="solution-1">Solution</h3>
<pre><code class="language-jsx">function findAverage(array) {
  // 주어진 목록에 있는 숫자의 평균을 계산하는 함수를 작성하세요.
  //참고: 빈 배열은 0을 반환해야 합니다.
  // your code here

  let sum = 0;
  let divide = array.length;

  const result = array.map((item) =&gt; {
    return  sum += item
  })


  if(array.length === 0){
    return 0
  } else {
    return sum / divide
  }

}</code></pre>
<pre><code class="language-jsx">var find_average = (array) =&gt; {  
  return array.length === 0 ? 0 : array.reduce((acc, ind)=&gt; acc + ind, 0)/array.length
}</code></pre>
<pre><code class="language-jsx">function find_average(array) {
  if (array.length === 0) {
  return 0;
  }
  var result = 0;
  for (i=0; i&lt;array.length; i++) {
    result +=array[i];
  }
  return result/array.length;
}</code></pre>
<pre><code class="language-jsx">function find_average(arr) {
    return arr.length &gt; 0? arr.reduce((a, b) =&gt; a + b) / arr.length : 0;
}</code></pre>
<h2 id="8-kyu---sentence-smash">8 kyu - <strong>Sentence Smash</strong></h2>
<p>Write a function that takes an array of words and smashes them 
together into a sentence and returns the sentence. You can ignore any 
need to sanitize words or add punctuation, but you should add spaces 
between each word. <strong>Be careful, there shouldn&#39;t be a space at the beginning or the end of the sentence!</strong></p>
<h2 id="example">Example</h2>
<pre><code>[&#39;hello&#39;, &#39;world&#39;, &#39;this&#39;, &#39;is&#39;, &#39;great&#39;]  =&gt;  &#39;hello world this is great&#39;
</code></pre><h3 id="solution-2">Solution</h3>
<pre><code class="language-jsx">function smash (words) {
  // 단어 배열을 받아 한 문장으로 뭉쳐서 문장을 반환하는 함수를 작성합니다. 
  // 단어를 띄어쓰거나 구두점을 추가할 필요는 없지만 각 단어 사이에 공백을 추가해야 합니다. 
  // 문장의 시작이나 끝에 공백이 있으면 안 되니 주의하세요!
  return words.join(&quot; &quot;);
};</code></pre>
<pre><code class="language-jsx">// Smash Words
const smash = words =&gt; words.join(&#39; &#39;);</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[[알고리즘] 2024-02-13(화)]]></title>
            <link>https://velog.io/@dev-riverkim/%EC%95%8C%EA%B3%A0%EB%A6%AC%EC%A6%98-2024-02-13%ED%99%94</link>
            <guid>https://velog.io/@dev-riverkim/%EC%95%8C%EA%B3%A0%EB%A6%AC%EC%A6%98-2024-02-13%ED%99%94</guid>
            <pubDate>Wed, 13 Mar 2024 23:20:02 GMT</pubDate>
            <description><![CDATA[<h2 id="8-kyu---even-or-odd">8 kyu - Even or Odd</h2>
<p>Create a function that takes an integer as an argument and returns <code>&quot;Even&quot;</code> for even numbers or <code>&quot;Odd&quot;</code> for odd numbers.</p>
<h3 id="solution">Solution</h3>
<pre><code class="language-jsx">function evenOrOdd(number) {
  return number % 2 === 0 ? &quot;Even&quot; : &quot;Odd&quot;
}</code></pre>
<pre><code class="language-jsx">const evenOrOdd = (number) =&gt; number % 2 ? &quot;Odd&quot; : &#39;Even&#39;;</code></pre>
<h2 id="8-kyu---transportation-on-vacation">8 kyu - <strong>Transportation on vacation</strong></h2>
<p>After a hard quarter in the office you decide to get some rest on a vacation. So you will book a flight for you and your girlfriend and try to leave all the mess behind you.</p>
<p>You will need a rental car in order for you to get around in your vacation. The manager of the car rental makes you some good offers.</p>
<p>Every day you rent the car costs $40. If you rent the car for 7 or more days, you get $50 off your total. Alternatively, if you rent the car for 3 or more days, you get $20 off your total.</p>
<p>Write a code that gives out the total amount for different days(d).</p>
<h3 id="solution-1">Solution</h3>
<pre><code class="language-jsx">function rentalCarCost(d) {
  // Your solution here
  //하루 렌트비는 $40입니다.
  //7일 이상 렌터카를 대여하면 총 금액에서 $50 할인을 받을 수 있습니다.
  //또는 3일 이상 렌터카를 렌트하면 총 금액에서 $20 할인을 받을 수 있습니다.

  //다른 날짜(d)에 대한 총 금액을 제공하는 코드를 작성하세요.

  if(d &gt;= 7){
   return (d * 40) - 50;
  } else if(d &gt;= 3){
  return (d * 40) - 20;
  } else {
    return d * 40
  }

}</code></pre>
<pre><code class="language-jsx">function baseCost(days, rate) {
  return days * rate;
}

function discountRate(days) {
  if ( days &gt;= 7 ) {
    return 50;
  }
  else if ( days &gt;= 3 ) {
    return 20;
  }
  else {
    return 0;
  }
}

function rentalCarCost(days) {
  return baseCost(days, 40) - discountRate(days);
}</code></pre>
<pre><code class="language-jsx">const rentalCarCost = d =&gt; d * 40 - ((d &gt; 6) ? 50 : ((d &gt; 2) ? 20 : 0));</code></pre>
<pre><code class="language-jsx">function rentalCarCost(d) {
  return d * 40 - (d &gt;= 7 ? 50 : (d &gt;= 3 ? 20 : 0));
}</code></pre>
<pre><code class="language-jsx">function rentalCarCost(d) {
  if(d&lt;3) return d * 40;
  if(7&gt;d &amp;&amp; d&gt;=3) return (d*40 -20);
  if(d&gt;=7) return (d*40 -50);
}</code></pre>
<pre><code class="language-jsx">function rentalCarCost(days) {
    var dayCost = 40;

    var discount = 0;
    if(days &gt;= 3) discount += 20;
    if(days &gt;= 7) discount += 30;

    return dayCost * days - discount;
}</code></pre>
<h2 id="8-kyu---l1-set-alarm">8 kyu - <strong>L1: Set Alarm</strong></h2>
<p>Write a function named <code>setAlarm</code>/<code>set_alarm</code>/<code>set-alarm</code>/<code>setalarm</code> (depending on language) which receives two parameters. The first parameter, <code>employed</code>, is true whenever you are employed and the second parameter, <code>vacation</code> is true whenever you are on vacation.</p>
<p>The function should return true if you are employed and not on 
vacation (because these are the circumstances under which you need to 
set an alarm). It should return false otherwise. Examples:</p>
<pre><code>employed | vacation
true     | true     =&gt; false
true     | false    =&gt; true
false    | true     =&gt; false
false    | false    =&gt; false
</code></pre><h3 id="solution-2">Solution</h3>
<pre><code class="language-jsx">function setAlarm(employed, vacation){
  return employed === true &amp;&amp; vacation === false ? true : false
}</code></pre>
<pre><code class="language-jsx">const setAlarm = (employed, vacation) =&gt; employed &amp;&amp; !vacation;</code></pre>
<pre><code class="language-jsx">function setAlarm(employed, vacation){
  return employed &amp;&amp; !vacation;
}</code></pre>
<pre><code class="language-jsx">function setAlarm(employed, vacation){
  return (employed &amp;&amp; !vacation) ? true : false;
}</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[[알고리즘] 2024-02-06(화)]]></title>
            <link>https://velog.io/@dev-riverkim/%EC%95%8C%EA%B3%A0%EB%A6%AC%EC%A6%98-2024-02-06%ED%99%94</link>
            <guid>https://velog.io/@dev-riverkim/%EC%95%8C%EA%B3%A0%EB%A6%AC%EC%A6%98-2024-02-06%ED%99%94</guid>
            <pubDate>Wed, 13 Mar 2024 23:17:38 GMT</pubDate>
            <description><![CDATA[<h2 id="8-kyu---filter-out-the-geese">8 kyu - Filter out the geese</h2>
<p>Write a function that takes a list of strings as an argument and returns a 
filtered list containing the same elements but with the &#39;geese&#39; removed.</p>
<p>The geese are any strings in the following array, which is pre-populated in your solution:</p>
<pre><code>  [&quot;African&quot;, &quot;Roman Tufted&quot;, &quot;Toulouse&quot;, &quot;Pilgrim&quot;, &quot;Steinbacher&quot;]</code></pre><p>For example, if this array were passed as an argument:</p>
<pre><code> [&quot;Mallard&quot;, &quot;Hook Bill&quot;, &quot;African&quot;, &quot;Crested&quot;, &quot;Pilgrim&quot;, &quot;Toulouse&quot;, &quot;Blue Swedish&quot;]</code></pre><p>Your function would return the following array:</p>
<pre><code>[&quot;Mallard&quot;, &quot;Hook Bill&quot;, &quot;Crested&quot;, &quot;Blue Swedish&quot;]</code></pre><p>The elements in the returned array should be in the same order as in 
the initial array passed to your function, albeit with the &#39;geese&#39; 
removed. Note that all of the strings will be in the same case as those 
provided, and some elements may be repeated.</p>
<h3 id="solution">Solution</h3>
<pre><code class="language-jsx">function gooseFilter (birds) {
  var geese = [&quot;African&quot;, &quot;Roman Tufted&quot;, &quot;Toulouse&quot;, &quot;Pilgrim&quot;, &quot;Steinbacher&quot;];
  return birds.filter(x=&gt; !geese.includes(x))
};</code></pre>
<pre><code class="language-jsx">function gooseFilter (birds) {
  var geese = [&quot;African&quot;, &quot;Roman Tufted&quot;, &quot;Toulouse&quot;, &quot;Pilgrim&quot;, &quot;Steinbacher&quot;];
  return birds.filter(b =&gt; !geese.includes(b));
};</code></pre>
<pre><code class="language-jsx">function gooseFilter (birds) {
  var geese = [&quot;African&quot;, &quot;Roman Tufted&quot;, &quot;Toulouse&quot;, &quot;Pilgrim&quot;, &quot;Steinbacher&quot;];
  return birds.filter( bird =&gt; geese.indexOf(bird) &lt; 0 );
};</code></pre>
<h2 id="8-kyu---a-needle-in-the-haystack">8 kyu - A Needle in the Haystack</h2>
<p>Can you find the needle in the haystack?</p>
<p>Write a function <code>findNeedle()</code> that takes an <code>array</code> full of junk but containing one <code>&quot;needle&quot;</code></p>
<p>After your function finds the needle it should return a message (as a string) that says:</p>
<p><code>&quot;found the needle at position &quot;</code> plus the <code>index</code> it found the needle, so:</p>
<p><strong>Example(Input --&gt; Output)</strong></p>
<pre><code>[&quot;hay&quot;, &quot;junk&quot;, &quot;hay&quot;, &quot;hay&quot;, &quot;moreJunk&quot;, &quot;needle&quot;, &quot;randomJunk&quot;] --&gt; &quot;found the needle at position 5&quot;
</code></pre><p><strong>Note: In COBOL, it should return</strong> <code>&quot;found the needle at position 6&quot;</code></p>
<h3 id="solution-1">Solution</h3>
<pre><code class="language-jsx">function findNeedle(haystack) {

  const index = haystack.findIndex((element, index, arr) =&gt; element === &#39;needle&#39;);

  return `found the needle at position ${index}`

}</code></pre>
<pre><code class="language-jsx">function findNeedle(haystack) {
  return &quot;found the needle at position &quot; + haystack.indexOf(&quot;needle&quot;);
}</code></pre>
<pre><code class="language-jsx">const findNeedle = haystack =&gt; `found the needle at position ${haystack.indexOf(&#39;needle&#39;)}`;</code></pre>
<h2 id="7-kyu---binary-addition">7 kyu - <strong>Binary Addition</strong></h2>
<p>mplement a function that adds two numbers together and returns their 
sum in binary. The conversion can be done before, or after the addition.</p>
<p>The binary number returned should be a string.</p>
<p><strong>Examples:(Input1, Input2 --&gt; Output (explanation)))</strong></p>
<pre><code>1, 1 --&gt; &quot;10&quot; (1 + 1 = 2 in decimal or 10 in binary)
5, 9 --&gt; &quot;1110&quot; (5 + 9 = 14 in decimal or 1110 in binary)</code></pre><h3 id="solution-2">Solution</h3>
<pre><code class="language-jsx">function addBinary(a,b) {
  // 10진수를 2진수로 변경

  return (a+b).toString(2)

}</code></pre>
<p>자바스크립트에서는 toString() 과parseInt() 를 이용해 손쉽게 숫자 진수들을 변환 할 수 있다.</p>
<p><img src="https://velog.velcdn.com/images/dev-riverkim/post/fc49f144-644c-407b-b756-9a06faa0bd55/image.png" alt=""></p>
<pre><code class="language-jsx">var decimal = 1023; 

var binary = decimal.toString(2);    // 2진수로
var octal = decimal.toString(8);    // 8진수로
var hex = decimal.toString(16);        // 16진수로</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[[알고리즘] 2024-02-05(월)]]></title>
            <link>https://velog.io/@dev-riverkim/%EC%95%8C%EA%B3%A0%EB%A6%AC%EC%A6%98-2024-02-05%EC%9B%94</link>
            <guid>https://velog.io/@dev-riverkim/%EC%95%8C%EA%B3%A0%EB%A6%AC%EC%A6%98-2024-02-05%EC%9B%94</guid>
            <pubDate>Wed, 13 Mar 2024 23:16:41 GMT</pubDate>
            <description><![CDATA[<h2 id="8-kyu---are-you-playing-banjo">8 kyu - Are You Playing Banjo?</h2>
<p>Create a function which answers the question &quot;Are you playing banjo?&quot;.</p>
<p>If your name starts with the letter &quot;R&quot; or lower case &quot;r&quot;, you are playing banjo!</p>
<p>The function takes a name as its only argument, and returns one of the following strings:</p>
<pre><code>name + &quot; plays banjo&quot;
name + &quot; does not play banjo&quot;</code></pre><p>Names given are always valid strings.</p>
<h3 id="solution">Solution</h3>
<pre><code class="language-jsx">function areYouPlayingBanjo(name) {
  return name[0] === &#39;R&#39; || name[0] === &#39;r&#39; ? `${name} plays banjo` : `${name} does not play banjo` ;
}</code></pre>
<pre><code class="language-jsx">function areYouPlayingBanjo(name) {
  return name + (name[0].toLowerCase() == &#39;r&#39; ? &#39; plays&#39; : &#39; does not play&#39;) + &quot; banjo&quot;;
}</code></pre>
<pre><code class="language-jsx">function areYouPlayingBanjo(name) {
  if (name[0].toLowerCase() === &#39;r&#39;) {
    return name + &#39; plays banjo&#39;;
  } else {
    return name + &#39; does not play banjo&#39;;
  }
}</code></pre>
<h2 id="8-kyu---third-angle-of-a-triangle">8 kyu - <strong>Third Angle of a Triangle</strong></h2>
<p>You are given two interior angles (in degrees) of a triangle.</p>
<p>Write a function to return the 3rd.</p>
<p>Note: only positive integers will be tested.</p>
<p><a href="https://en.wikipedia.org/wiki/Triangle">https://en.wikipedia.org/wiki/Triangle</a></p>
<h3 id="solution-1">Solution</h3>
<pre><code class="language-jsx">function otherAngle(a, b) {
  return 180 - (a + b);
}</code></pre>
<pre><code class="language-jsx">const otherAngle = (a, b) =&gt; 180 - a - b</code></pre>
<h2 id="8-kyu---fake-binary">8 kyu - Fake Binary</h2>
<p>Given a string of digits, you should replace any digit below 5 with &#39;0&#39; and any 
digit 5 and above with &#39;1&#39;. Return the resulting string.</p>
<p><strong>Note: input will never be an empty string</strong></p>
<h3 id="solution-2">Solution</h3>
<pre><code class="language-jsx">function fakeBin(x){
//숫자 문자열이 주어지면 5 이하의 숫자는 &#39;0&#39;으로, 5 이상의 숫자는 &#39;1&#39;로 바꿔야 합니다. 결과 문자열을 반환합니다.
//참고: 입력은 절대 빈 문자열이 될 수 없습니다.

  const str = x.split(&quot;&quot;);
  const result = str.map((i)=&gt;{
    return Number(i) &gt;= 5 ? 1:0
  });

return result.join(&quot;&quot;)
}</code></pre>
<pre><code class="language-jsx">function fakeBin(x) {
    return x.split(&#39;&#39;).map(n =&gt; n &lt; 5 ? 0 : 1).join(&#39;&#39;);
}</code></pre>
<pre><code class="language-jsx">function fakeBin(x) {
  return x.replace(/\d/g, d =&gt; d &lt; 5 ? 0 : 1);
}</code></pre>
<h2 id="8-kyu---grasshopper---personalized-message">8 kyu - <strong>Grasshopper - Personalized Message</strong></h2>
<p>Create a function that gives a personalized greeting. This function takes two parameters: <code>name</code> and <code>owner</code>.</p>
<p>Use conditionals to return the proper message:</p>
<table>
<thead>
<tr>
<th>case</th>
<th>return</th>
</tr>
</thead>
<tbody><tr>
<td>name equals owner</td>
<td>&#39;Hello boss&#39;</td>
</tr>
<tr>
<td>otherwise</td>
<td>&#39;Hello guest&#39;</td>
</tr>
</tbody></table>
<h3 id="solution-3">Solution</h3>
<pre><code class="language-jsx">function greet (name, owner) {
  return `Hello ${name === owner ? &#39;boss&#39; : &#39;guest&#39;}` 
}</code></pre>
<pre><code class="language-jsx">function greet (name, owner) {
  return name === owner ? &#39;Hello boss&#39; :     &#39;Hello guest&#39;;
}</code></pre>
<h2 id="8-kyu-grasshopper---terminal-game-move-function">8 kyu Grasshopper - Terminal game move function</h2>
<h2 id="terminal-game-move-function">Terminal game move function</h2>
<p>In this game, the hero moves from left to right. The player rolls the dice and moves the number of spaces indicated by the dice <strong>two times</strong>.</p>
<p>Create a function for the terminal game that takes the current 
position of the hero and the roll (1-6) and return the new position.</p>
<h3 id="example">Example:</h3>
<pre><code class="language-python">move(3, 6) should equal 15</code></pre>
<h3 id="solution-4">Solution</h3>
<pre><code class="language-jsx">function move (position, roll) {
  // return the new position
  return position + (roll*2)
}</code></pre>
<pre><code class="language-jsx">const move = (position, roll) =&gt; position + roll * 2</code></pre>
<pre><code class="language-jsx">function move (position, roll) {
  return position + roll * 2
}</code></pre>
<h2 id="8-kyu---grasshopper---check-for-factor">8 kyu - <strong>Grasshopper - Check for factor</strong></h2>
<p>This function should test if the <code>factor</code> is a factor of <code>base</code>.</p>
<p>Return <code>true</code> if it is a factor or <code>false</code> if it is not.</p>
<h2 id="about-factors">About factors</h2>
<p>Factors are numbers you can multiply together to get another number.</p>
<p>2 and 3 are factors of 6 because: <code>2 * 3 = 6</code></p>
<ul>
<li>You can find a factor by dividing numbers. If the remainder is 0 then the number is a factor.</li>
<li>You can use the mod operator (<code>%</code>) in most languages to check for a remainder</li>
</ul>
<p>For example 2 is not a factor of 7 because: <code>7 % 2 = 1</code></p>
<p>Note: <code>base</code> is a non-negative number, <code>factor</code> is a positive number.</p>
<h3 id="solution-5">Solution</h3>
<pre><code class="language-jsx">function checkForFactor (base, factor) {
  return base % factor === 0 ? true : false
}</code></pre>
<pre><code class="language-jsx">function checkForFactor (base, factor) {
  return base % factor === 0;
}</code></pre>
<pre><code class="language-jsx">const checkForFactor = (base, factor) =&gt; base % factor === 0;</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[[알고리즘] 2024-02-01(목)]]></title>
            <link>https://velog.io/@dev-riverkim/%EC%95%8C%EA%B3%A0%EB%A6%AC%EC%A6%98-2024-02-01%EB%AA%A9</link>
            <guid>https://velog.io/@dev-riverkim/%EC%95%8C%EA%B3%A0%EB%A6%AC%EC%A6%98-2024-02-01%EB%AA%A9</guid>
            <pubDate>Wed, 13 Mar 2024 23:14:40 GMT</pubDate>
            <description><![CDATA[<h1 id="8-kyu---reversed-strings">8 kyu - <strong>Reversed Strings</strong></h1>
<p>Complete the solution so that it reverses the string passed into it.</p>
<pre><code class="language-jsx">&#39;world&#39;  =&gt;  &#39;dlrow&#39;
&#39;word&#39;   =&gt;  &#39;drow&#39;</code></pre>
<h3 id="solution">Solution</h3>
<pre><code class="language-jsx">function solution(str){
  return str.split(&#39;&#39;).reverse().join(&#39;&#39;)
}</code></pre>
<pre><code class="language-jsx">const solution = s =&gt; [...s].reverse().join(&#39;&#39;)</code></pre>
<h2 id="8-kyu---convert-boolean-values-to-strings-yes-or-no">8 kyu - <strong>Convert boolean values to strings &#39;Yes&#39; or &#39;No&#39;.</strong></h2>
<p>Complete the method that takes a boolean value and return a <code>&quot;Yes&quot;</code> string for <code>true</code>, or a <code>&quot;No&quot;</code> string for <code>false</code>.</p>
<h3 id="solution-1">Solution</h3>
<pre><code class="language-jsx">function boolToWord( bool ){
  return bool === true ? &quot;Yes&quot; : &quot;No&quot;
}</code></pre>
<pre><code class="language-jsx">function boolToWord( bool ){
  return bool ? &#39;Yes&#39;:&#39;No&#39;;
}</code></pre>
<pre><code class="language-jsx">let boolToWord = bool =&gt; bool ? &#39;Yes&#39; : &#39;No&#39;;</code></pre>
<h2 id="8-kyu---you-cant-code-under-pressure-1">8 kyu - <strong>You Can&#39;t Code Under Pressure #1</strong></h2>
<p>Code as fast as you can! You need to double the integer and return it.</p>
<h3 id="solution-2">Solution</h3>
<pre><code class="language-jsx">function doubleInteger(i) {
  // i will be an integer. Double it and return it.
  return i * 2;
}</code></pre>
<pre><code class="language-jsx">function doubleInteger(i) {
  // i will be an integer. Double it and return it.
  return i+i;
}</code></pre>
<h2 id="8-kyu---makeuppercase">8 kyu - <strong>MakeUpperCase</strong></h2>
<p>Write a function which converts the input string to uppercase.</p>
<h3 id="solution-3">Solution</h3>
<pre><code class="language-jsx">function makeUpperCase(str) {
  return str.toUpperCase()
}</code></pre>
<h2 id="8-kyu---grasshopper---grade-book">8 kyu - <strong>Grasshopper - Grade book</strong></h2>
<h2 id="grade-book">Grade book</h2>
<p>Complete the function so that it finds the average of the three 
scores passed to it and returns the letter value associated with that 
grade.</p>
<table>
<thead>
<tr>
<th>Numerical Score</th>
<th>Letter Grade</th>
</tr>
</thead>
<tbody><tr>
<td>90 &lt;= score &lt;= 100</td>
<td>&#39;A&#39;</td>
</tr>
<tr>
<td>80 &lt;= score &lt; 90</td>
<td>&#39;B&#39;</td>
</tr>
<tr>
<td>70 &lt;= score &lt; 80</td>
<td>&#39;C&#39;</td>
</tr>
<tr>
<td>60 &lt;= score &lt; 70</td>
<td>&#39;D&#39;</td>
</tr>
<tr>
<td>0 &lt;= score &lt; 60</td>
<td>&#39;F&#39;</td>
</tr>
</tbody></table>
<p>Tested values are all between 0 and 100. Theres is no need to check for negative values or values greater than 100.</p>
<h3 id="solution-4">Solution</h3>
<pre><code class="language-jsx">function getGrade (s1, s2, s3) {
  let score = (s1+s2+s3)/3

  if(score &gt;= 90) {
    return &#39;A&#39;
  } else if (score &gt;= 80){
    return &#39;B&#39;
  } else if(score &gt;= 70){
    return &#39;C&#39;
  } else if(score &gt;= 60){
    return &#39;D&#39;
  } else {
    return &#39;F&#39;
  }
}</code></pre>
<pre><code class="language-jsx">function getGrade (s1, s2, s3) {
     let score = (s1 + s2 + s3) / 3;
     if (score &gt;= 90) {
         return &#39;A&#39;;
     }
     if (score &gt;= 80) {
         return &#39;B&#39;;
     }
     if (score &gt;= 70) {
         return &#39;C&#39;;
     }
     if (score &gt;= 60) {
         return &#39;D&#39;;
     }
     return &#39;F&#39;;
}</code></pre>
<pre><code class="language-jsx">function getGrade (s1, s2, s3) {
  avg = (s1+s2+s3)/3;
  if (avg &lt; 60)  return &quot;F&quot;;
    else if (avg &lt; 70) return &quot;D&quot;;
    else if (avg &lt; 80) return &quot;C&quot;;
    else if (avg &lt; 90) return &quot;B&quot;;
    else return &quot;A&quot;;
}</code></pre>
<pre><code class="language-jsx">function getGrade (s1, s2, s3) {
  var s = (s1 + s2 + s3) / 3
  return s &gt;= 90 ? &quot;A&quot; : s &gt;= 80 ? &quot;B&quot; : s &gt;= 70 ? &quot;C&quot; : s &gt;= 60 ? &quot;D&quot; : &quot;F&quot;
}</code></pre>
<h2 id="7-kyu---number-of-people-in-the-bus">7 kyu - <strong>Number of People in the Bus</strong></h2>
<p>There is a bus moving in the city which takes and drops some people at each bus stop.</p>
<p>You are provided with a list (or array) of integer pairs. Elements of each pair represent the number of people that get on the bus (the first item) and the number of people that get off the bus (the second item) at a bus stop.</p>
<p>Your task is to return the number of people who are still on the bus after the last bus stop (after the last array). Even though it is the last bus stop, the bus might not be empty and some people might still be inside the bus, they are probably sleeping there :D</p>
<p>Take a look on the test cases.</p>
<p>Please keep in mind that the test cases ensure that the number of people in the bus is always &gt;= 0. So the returned integer can&#39;t be negative.</p>
<p>The second value in the first pair in the array is 0, since the bus is empty in the first bus stop.</p>
<h3 id="solution-5">Solution</h3>
<pre><code class="language-jsx">var number = function(busStops){
  // Good Luck!
//  도시에는 각 버스 정류장에서 일부 사람들을 태우고 내리는 버스가 있습니다.
//  정수 쌍의 목록(또는 배열)이 제공됩니다.  각 쌍의 요소는 버스에 타는 사람의 수(첫 번째 항목)와 버스 정류장에서 버스에서 내리는 사람의 수(두 번째 항목)를 나타냅니다.
//  당신의 임무는 마지막 버스 정류장 이후(마지막 배열 이후) 버스에 아직 남아 있는 사람들의 수를 반환하는 것입니다.  
// 마지막 정류장임에도 불구하고 버스가 비어있지 않을 수도 있고, 아직 버스 안에 사람들이 있을 수도 있고, 아마 거기서 자고 있을 수도 있어요 :D

//  테스트 케이스를 살펴보세요.

  console.log(busStops)

  // 배열을 돌면서 첫번째 자릿수를 더하고
  // 배열을 돌면서 두번째 자리수를 더해서

  // 두 값의 차이를 결과로 반환

  let value1 = 0;
  let value2 = 0;
  let a = busStops.map((i)=&gt;{

      value1 += i[0]
      value2 += i[1]
  })

  return value1 - value2
}</code></pre>
<pre><code class="language-jsx">const number = (busStops) =&gt; busStops.reduce((rem, [on, off]) =&gt; rem + on - off, 0);</code></pre>
<pre><code class="language-jsx">var number = function(busStops){
    var totalPeople = 0;
  for (var i=0; i&lt;busStops.length; i++) {
      totalPeople += busStops[i][0];
    totalPeople -= busStops[i][1];
  }
  return totalPeople;
}</code></pre>
<pre><code class="language-jsx">var number = function(busStops){
  // Good Luck!
  var num=0;
  for(var i=0;i&lt;busStops.length;i++){
      num+=busStops[i][0]-busStops[i][1]
  }
  return num;
}</code></pre>
<h2 id="7-kyu---mumbling">7 kyu - <strong>Mumbling</strong></h2>
<p>This time no story, no theory. The examples below show you how to write function <code>accum</code>:</p>
<h3 id="examples">Examples:</h3>
<pre><code>accum(&quot;abcd&quot;) -&gt; &quot;A-Bb-Ccc-Dddd&quot;
accum(&quot;RqaEzty&quot;) -&gt; &quot;R-Qq-Aaa-Eeee-Zzzzz-Tttttt-Yyyyyyy&quot;
accum(&quot;cwAt&quot;) -&gt; &quot;C-Ww-Aaa-Tttt&quot;</code></pre><p>The parameter of accum is a string which includes only letters from <code>a..z</code> and <code>A..Z</code>.</p>
<h3 id="solution-6">Solution</h3>
<pre><code class="language-jsx">function accum(s) {

  // 문자열을 입력받고 소문자로 변경한 뒤
  // 배열로 쪼갠 뒤 배열의 자릿수 만큼 문자열을 반복

  const list = s.toLowerCase().split(&quot;&quot;)
  const newList = list.map((i,z)=&gt;{
    return  i.toUpperCase() + i.toLowerCase().repeat(z)
  })

  return newList.join(&quot;-&quot;)

}</code></pre>
<pre><code class="language-jsx">function accum(s) {
    return s.split(&#39;&#39;).map((c, i) =&gt; (c.toUpperCase() + c.toLowerCase().repeat(i))).join(&#39;-&#39;);
}</code></pre>
<pre><code class="language-jsx">function accum(s) {
    return s.split(&#39;&#39;).map((x,index) =&gt; x.toUpperCase()+Array(index+1).join(x.toLowerCase())).join(&#39;-&#39;);
}</code></pre>
<pre><code class="language-jsx">function accum(str) {
    var letters = str.split(&#39;&#39;);
  var result = [];
  for (var i = 0; i &lt; letters.length; i++) {
    result.push(letters[i].toUpperCase() + Array(i + 1).join(letters[i].toLowerCase()));
  }
  return result.join(&#39;-&#39;);
}</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[[bugfix]체크박스 / 라디오 선택 시 상단 스크롤 이동 문제]]></title>
            <link>https://velog.io/@dev-riverkim/bugfix%EC%B2%B4%ED%81%AC%EB%B0%95%EC%8A%A4-%EB%9D%BC%EB%94%94%EC%98%A4-%EC%84%A0%ED%83%9D-%EC%8B%9C-%EC%83%81%EB%8B%A8-%EC%8A%A4%ED%81%AC%EB%A1%A4-%EC%9D%B4%EB%8F%99-%EB%AC%B8%EC%A0%9C</link>
            <guid>https://velog.io/@dev-riverkim/bugfix%EC%B2%B4%ED%81%AC%EB%B0%95%EC%8A%A4-%EB%9D%BC%EB%94%94%EC%98%A4-%EC%84%A0%ED%83%9D-%EC%8B%9C-%EC%83%81%EB%8B%A8-%EC%8A%A4%ED%81%AC%EB%A1%A4-%EC%9D%B4%EB%8F%99-%EB%AC%B8%EC%A0%9C</guid>
            <pubDate>Mon, 18 Dec 2023 04:31:10 GMT</pubDate>
            <description><![CDATA[<p>인풋박스 선택 시 스크롤이 상단으로 이동하는 버그</p>
<p>CSS로 라디오 버튼을 숨긴 경우에 주로 발생</p>
<p>라디오 버튼 숨김 CSS</p>
<pre><code class="language-scss">.radio_box input {
    position: absolute;
    top: -9999px;
    width: 1px;
    height: 1px;
    margin: -1px;
    overflow: hidden;
    opacity: 0;
    clip-path: polygon(0 0, 0 0, 0 0)
}</code></pre>
<pre><code class="language-scss">.radio_box input {
    position: absolute;
    top: -9999px;
    width: 1px;
    height: 1px;
    margin: -1px;
    overflow: hidden;
    opacity: 0;
    clip-path: polygon(0 0, 0 0, 0 0)
}


// 해결방법들

// 라디오버튼 일 경우
input[type=&quot;radio&quot;] {
    display: none
}

// 체크박스 일 경우
input[type=&quot;checkbox&quot;] {
    display: none
}

//  visibility: hidden; 추가
//  top 값을 할당하지 않거나 &#39;auto&#39;

.hiddenInput {
  opacity: 0;
  height: 0;
  width: 0;
  margin: 0;
  padding: 0;
  position: fixed;
  top: 0;
}



</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[[bugfix]ios 저전력모드(Low Power Mode) video 재생 문제]]></title>
            <link>https://velog.io/@dev-riverkim/ios-%EC%A0%80%EC%A0%84%EB%A0%A5%EB%AA%A8%EB%93%9CLow-Power-Mode-video-%EC%9E%AC%EC%83%9D-%EB%AC%B8%EC%A0%9C</link>
            <guid>https://velog.io/@dev-riverkim/ios-%EC%A0%80%EC%A0%84%EB%A0%A5%EB%AA%A8%EB%93%9CLow-Power-Mode-video-%EC%9E%AC%EC%83%9D-%EB%AC%B8%EC%A0%9C</guid>
            <pubDate>Mon, 30 Oct 2023 06:22:03 GMT</pubDate>
            <description><![CDATA[<p><img src="https://velog.velcdn.com/images/dev-riverkim/post/581da907-4803-4620-8795-7cc170a73e85/image.jpeg" alt=""></p>
<p>저전력 모드일 때 배터리 잔량이 노란색으로 표시 됨</p>
<pre><code class="language-javascript">
const video = document.getElementById(&#39;myVideo&#39;);
video.addEventListener(&#39;suspend&#39;, () =&gt; {
  // We&#39;re in low-power mode, show fallback UI
});
video.addEventListener(&#39;play&#39;, () =&gt; {
  // Remove fallback UI if user plays video manually
});
</code></pre>
<pre><code class="language-javascript">
const myVideo = document.getElementById(&quot;myVideo&quot;);

myVideo
  .play()
  .then(() =&gt; {
    console.log(&quot;저전력 모드 아님&quot;);
  })
  .catch((error) =&gt; {
    console.log(error, &quot;저전력모드&quot;);
    // do something
  });



var promise = document.querySelector(&#39;video&#39;).play();

if (promise !== undefined) {
  promise.then(_ =&gt; {
    // 자동 재생 시작!
  }).catch(error =&gt; {
     // 자동 재생이 막힘.
     promise.style.display = &#39;none&#39;;
  });
}


const video = document.querySelector(&quot;video&quot;);
 if (video.paused) {
      video.style.display = &#39;none&#39;;
}</code></pre>
<p>운영 배포 시 코드
video의 poster 속성을 가져와서 img 태그를 만들어서 넣어줌</p>
<pre><code class="language-javascript">
function handleIOSLowPowerMode(videoTag) {
    videoTag.play()
        .then(() =&gt; {
            // 비디오 재생 성공
        })
        .catch((error) =&gt; {
            // 비디오 재생 실패 (저전력 모드)
            const posterSrc = videoTag.getAttribute(&#39;poster&#39;);
            const imgElem = document.createElement(&#39;img&#39;);
            imgElem.src = posterSrc;
            imgElem.alt = &#39;alt을 넣어줍니다.&#39;;
            imgElem.style.width = &#39;100%&#39;;

            // 비디오 요소를 이미지 요소로 대체
            videoTag.parentNode.replaceChild(imgElem, videoTag);
        });
}

// 사용
const videoElem = document.querySelector(&#39;.video&#39;);
handleIOSLowPowerMode(videoElem);</code></pre>
<p><a href="https://logfetch.com/html-autoplay/">https://logfetch.com/html-autoplay/</a></p>
]]></description>
        </item>
        <item>
            <title><![CDATA[[scss]화면 크기에 따라 간격 조절]]></title>
            <link>https://velog.io/@dev-riverkim/scss%ED%99%94%EB%A9%B4-%ED%81%AC%EA%B8%B0%EC%97%90-%EB%94%B0%EB%9D%BC-%EA%B0%84%EA%B2%A9-%EC%A1%B0%EC%A0%88</link>
            <guid>https://velog.io/@dev-riverkim/scss%ED%99%94%EB%A9%B4-%ED%81%AC%EA%B8%B0%EC%97%90-%EB%94%B0%EB%9D%BC-%EA%B0%84%EA%B2%A9-%EC%A1%B0%EC%A0%88</guid>
            <pubDate>Mon, 23 Oct 2023 08:23:30 GMT</pubDate>
            <description><![CDATA[<p><img src="https://velog.velcdn.com/images/dev-riverkim/post/a26cc0bd-c68b-4a56-9d43-d246d46dea82/image.gif" alt=""></p>
<p>예시 gif는 크림 화면</p>
<p>이미지 크기는 유지하고 간격이 늘어나 도록</p>
<pre><code class="language-html">&lt;div class=&quot;box&quot;&gt;
    &lt;a href=&quot;#&quot;&gt;
        &lt;span class=&quot;img_wrap&quot;&gt;
            &lt;img src=&quot;https://dummyimage.com/300x200/000/fff&quot; alt=&quot;이미지1&quot; /&gt;
        &lt;/span&gt;
        &lt;p class=&quot;name&quot;&gt;이미지1&lt;/p&gt;
    &lt;/a&gt;
      &lt;a href=&quot;#&quot;&gt;
        &lt;span class=&quot;img_wrap&quot;&gt;
            &lt;img src=&quot;https://dummyimage.com/300x200/000/fff&quot; alt=&quot;이미지2&quot; /&gt;
        &lt;/span&gt;
        &lt;p class=&quot;name&quot;&gt;이미지2&lt;/p&gt;
    &lt;/a&gt;
      &lt;a href=&quot;#&quot;&gt;
        &lt;span class=&quot;img_wrap&quot;&gt;
            &lt;img src=&quot;https://dummyimage.com/300x200/000/fff&quot; alt=&quot;이미지3&quot; /&gt;
        &lt;/span&gt;
        &lt;p class=&quot;name&quot;&gt;이미지3&lt;/p&gt;
    &lt;/a&gt;
      &lt;a href=&quot;#&quot;&gt;
        &lt;span class=&quot;img_wrap&quot;&gt;
            &lt;img src=&quot;https://dummyimage.com/300x200/000/fff&quot; alt=&quot;이미지4&quot; /&gt;
        &lt;/span&gt;
        &lt;p class=&quot;name&quot;&gt;이미지4&lt;/p&gt;
    &lt;/a&gt;
      &lt;a href=&quot;#&quot;&gt;
        &lt;span class=&quot;img_wrap&quot;&gt;
            &lt;img src=&quot;https://dummyimage.com/300x200/000/fff&quot; alt=&quot;이미지5&quot; /&gt;
        &lt;/span&gt;
        &lt;p class=&quot;name&quot;&gt;이미지5&lt;/p&gt;
    &lt;/a&gt;
      &lt;a href=&quot;#&quot;&gt;
        &lt;span class=&quot;img_wrap&quot;&gt;
            &lt;img src=&quot;https://dummyimage.com/300x200/000/fff&quot; alt=&quot;이미지6&quot; /&gt;
        &lt;/span&gt;
        &lt;p class=&quot;name&quot;&gt;이미지6&lt;/p&gt;
    &lt;/a&gt;
&lt;/div&gt;</code></pre>
<pre><code class="language-scss">.box {
    display: flex;
    gap: 12px 6px;
    flex-wrap: wrap;
    margin-top: 16px;
    padding: 0 12px;
    a {
        display: inline-flex;
        align-items: center;
        justify-content: flex-start;
        flex-direction: column;
        width: calc((100% - 12px) / 3);
        overflow: hidden;
        .img_wrap {
            width: 52px;
            height: 52px;
            overflow: hidden;
            border-radius: 12px;
            img {
                width: 100%;
                height: 100%;
            }
        }
        .name {
            margin-top: 8px;
            font-size: 12px;
            font-weight: $fw-regular;
            line-height: 1.33;
            color: $gray2;
            text-align: center;
        }
    }
}</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[[scss]화면 크기에 따라 이미지 비율 조절]]></title>
            <link>https://velog.io/@dev-riverkim/scss%EC%9D%B4%EB%AF%B8%EC%A7%80-%EB%B9%84%EC%9C%A8%EC%97%90-%EB%A7%9E%EA%B2%8C-%EC%B2%98%EB%A6%AC</link>
            <guid>https://velog.io/@dev-riverkim/scss%EC%9D%B4%EB%AF%B8%EC%A7%80-%EB%B9%84%EC%9C%A8%EC%97%90-%EB%A7%9E%EA%B2%8C-%EC%B2%98%EB%A6%AC</guid>
            <pubDate>Mon, 23 Oct 2023 07:59:08 GMT</pubDate>
            <description><![CDATA[<p><img src="https://velog.velcdn.com/images/dev-riverkim/post/3968b90d-d6d8-423a-a20a-85dff81554ed/image.gif" alt=""></p>
<p>크림 사이트 화면</p>
<p>간격은 유지하고 이미지 크기 조절</p>
<p>이미지 비율에 따라 padding-bottom 조절
현재 요구사항은 width:100px 일 때 hegith:64px</p>
<pre><code class="language-html">        &lt;div class=&quot;container&quot;&gt;
            &lt;a href=&quot;#&quot;&gt;
                &lt;div class=&quot;img_wrap&quot;&gt;
                    &lt;img src=&quot;https://dummyimage.com/300x200/000/fff&quot; alt=&quot;이미지1&quot; /&gt;
                &lt;/div&gt;
                &lt;p class=&quot;name&quot;&gt;이미지1&lt;/p&gt;
            &lt;/a&gt;
            &lt;a href=&quot;#&quot;&gt;
                &lt;div class=&quot;img_wrap&quot;&gt;
                    &lt;img src=&quot;https://dummyimage.com/300x200/000/fff&quot; alt=&quot;이미지1&quot; /&gt;
                &lt;/div&gt;
                &lt;p class=&quot;name&quot;&gt;이미지1&lt;/p&gt;
            &lt;/a&gt;
            &lt;a href=&quot;#&quot;&gt;
                &lt;div class=&quot;img_wrap&quot;&gt;
                    &lt;img src=&quot;https://dummyimage.com/300x200/000/fff&quot; alt=&quot;이미지1&quot; /&gt;
                &lt;/div&gt;
                &lt;p class=&quot;name&quot;&gt;이미지1&lt;/p&gt;
            &lt;/a&gt;
               &lt;a href=&quot;#&quot;&gt;
                &lt;div class=&quot;img_wrap&quot;&gt;
                    &lt;img src=&quot;https://dummyimage.com/300x200/000/fff&quot; alt=&quot;이미지1&quot; /&gt;
                &lt;/div&gt;
                &lt;p class=&quot;name&quot;&gt;이미지1&lt;/p&gt;
            &lt;/a&gt;
        &lt;/div&gt;</code></pre>
<pre><code class="language-scss">    .container {
        display: flex;
        justify-content: space-between;
        flex-wrap: wrap;
        gap: 16px 8px;
        a {
            display: block;
            width: calc((100% - 8px) / 2);
        }
        .img_wrap {
            position: relative;
            width: 100%;
            height: 0;
            padding-bottom: 64%;
            overflow: hidden;
            border-radius: 6px;
            img {
                position: absolute;
                left: 50%;
                top: 50%;
                transform: translate(-50%, -50%);
                width: 100%;
                height: 100%;
                z-index: 1;
                object-fit: cover;
            }
            &amp;::before{
                content: &quot;&quot;;
                @include thumOverDeem;
            }
        }
        .name {
            margin-top: 8px;
            font-size: 12px;
            font-weight: $fw-regular;
            line-height: 1.33;
            color: $gray2;
            text-align: center;
            @include single-ellipsis;
        }
    }</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[[vue] 글자수 기준으로 말줄임 처리]]></title>
            <link>https://velog.io/@dev-riverkim/vue-%EA%B8%80%EC%9E%90%EC%88%98-%EA%B8%B0%EC%A4%80%EC%9C%BC%EB%A1%9C-%EB%A7%90%EC%A4%84%EC%9E%84-%EC%B2%98%EB%A6%AC</link>
            <guid>https://velog.io/@dev-riverkim/vue-%EA%B8%80%EC%9E%90%EC%88%98-%EA%B8%B0%EC%A4%80%EC%9C%BC%EB%A1%9C-%EB%A7%90%EC%A4%84%EC%9E%84-%EC%B2%98%EB%A6%AC</guid>
            <pubDate>Mon, 23 Oct 2023 06:04:00 GMT</pubDate>
            <description><![CDATA[<pre><code class="language-vue">
&lt;template&gt;
    ...
    &lt;p class=&quot;name&quot;&gt;
       {{ item.name | truncateText(15) }}
     &lt;/p&gt;
    ...
&lt;/template&gt;

&lt;script&gt;

    export default {
        filters: {
            truncateText: function (value, limit) {
                if (value.length &gt; limit) {
                    return value.slice(0, limit) + &#39;...&#39;
                }
                return value
            }
        },
    }
&lt;/script&gt;</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[[javascript] iframe 컨텐츠의 높이에 맞게 높이 조정]]></title>
            <link>https://velog.io/@dev-riverkim/javascript-iframe-%EC%BB%A8%ED%85%90%EC%B8%A0%EC%9D%98-%EB%86%92%EC%9D%B4%EC%97%90-%EB%A7%9E%EA%B2%8C-%EB%86%92%EC%9D%B4-%EC%A1%B0%EC%A0%95</link>
            <guid>https://velog.io/@dev-riverkim/javascript-iframe-%EC%BB%A8%ED%85%90%EC%B8%A0%EC%9D%98-%EB%86%92%EC%9D%B4%EC%97%90-%EB%A7%9E%EA%B2%8C-%EB%86%92%EC%9D%B4-%EC%A1%B0%EC%A0%95</guid>
            <pubDate>Mon, 23 Oct 2023 05:23:06 GMT</pubDate>
            <description><![CDATA[<pre><code class="language-html">&lt;!DOCTYPE html&gt;
&lt;html lang=&quot;ko&quot;&gt;
&lt;meta name=&quot;viewport&quot;
    content=&quot;user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, width=device-width&quot;&gt;

&lt;head&gt;
    &lt;style&gt;
        * {
            padding: 0;
            margin: 0;
        }
    &lt;/style&gt;
&lt;/head&gt;

&lt;body&gt;
    &lt;iframe width=&quot;100%&quot; height=&quot;315&quot; src=&quot;https://www.youtube.com/embed/AgMptWkzRD4?si=SOaEOsHma3zhJjqW&quot;
        title=&quot;YouTube video player&quot; frameborder=&quot;0&quot;
        allow=&quot;accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share&quot;
        allowfullscreen id=&quot;myIframe&quot;&gt;&lt;/iframe&gt;


    &lt;script&gt;


        window.addEventListener(&#39;resize&#39;, () =&gt; {
            const screenWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
            const screenHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
            document.getElementById(&#39;myIframe&#39;).style.width = screenWidth + &#39;px&#39;;
            document.getElementById(&#39;myIframe&#39;).style.height = screenHeight + &#39;px&#39;;
        });

        window.dispatchEvent(new Event(&#39;resize&#39;));


    &lt;/script&gt;

&lt;/body&gt;

&lt;/html&gt;
</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[[setting] vue3 snippet - script태그가 먼저오도록 정렬]]></title>
            <link>https://velog.io/@dev-riverkim/setting-vue3-snippet-script%ED%83%9C%EA%B7%B8%EA%B0%80-%EB%A8%BC%EC%A0%80%EC%98%A4%EB%8F%84%EB%A1%9D-%EC%A0%95%EB%A0%AC</link>
            <guid>https://velog.io/@dev-riverkim/setting-vue3-snippet-script%ED%83%9C%EA%B7%B8%EA%B0%80-%EB%A8%BC%EC%A0%80%EC%98%A4%EB%8F%84%EB%A1%9D-%EC%A0%95%EB%A0%AC</guid>
            <pubDate>Mon, 23 Oct 2023 05:01:59 GMT</pubDate>
            <description><![CDATA[<p>vue-vscode-snippets 같은 플러그인을 사용할 때 만들어지는 snippet 정렬을 변경해보자</p>
<p>보통 아래와 같은 형식으로 snippet을 사용했으나</p>
<pre><code class="language-vue">&lt;template&gt;
  &lt;div&gt;

  &lt;/div&gt;
&lt;/template&gt;

&lt;script setup&gt;

&lt;/script&gt;

&lt;style scoped&gt;

&lt;/style&gt;</code></pre>
<p>최근에는 아래와 같은 형태로 많이 쓰이고 있음 (공식문서 참고 <a href="https://vuejs.org/style-guide/rules-recommended.html#single-file-component-top-level-element-order">https://vuejs.org/style-guide/rules-recommended.html#single-file-component-top-level-element-order</a>)</p>
<pre><code class="language-vue">&lt;script setup&gt;

&lt;/script&gt;

&lt;template&gt;
  &lt;div&gt;

  &lt;/div&gt;
&lt;/template&gt;

&lt;style scoped&gt;

&lt;/style&gt;</code></pre>
<p>작업 폴더 경로에 들어가서 터미널에 입력</p>
<p>mkdir -p .vscode &amp;&amp; curl -L <a href="https://raw.githubusercontent.com/sdras/vue-vscode-snippets/943ccfc9ba0b3b85d05dfc8b6f9e220db8ebc81e/snippets/vue.json">https://raw.githubusercontent.com/sdras/vue-vscode-snippets/943ccfc9ba0b3b85d05dfc8b6f9e220db8ebc81e/snippets/vue.json</a> -o .vscode/vue.json.code-snippets</p>
<p>.vscode 경로에 vue.json.code-snippets 파일이 생성되며</p>
<p>vue 파일에서 vbase~를 입력할 때 나오는 추천 snippet에  vbase-3-ts-setup-first 를 선택하면 <script></script>가 먼저 나오게 된다.</p>
<p>VSCode User Snippets에 관련된 내용을 찾으면 더 세세한 설정이 가능하다.</p>
<p><a href="https://musma.github.io/2019/08/12/vscode-code-snippets.html">https://musma.github.io/2019/08/12/vscode-code-snippets.html</a></p>
]]></description>
        </item>
        <item>
            <title><![CDATA[[scss] mixin - grid-columnizer]]></title>
            <link>https://velog.io/@dev-riverkim/scss-mixin</link>
            <guid>https://velog.io/@dev-riverkim/scss-mixin</guid>
            <pubDate>Mon, 23 Oct 2023 04:56:17 GMT</pubDate>
            <description><![CDATA[<p>상품 나열 등에 사용
<img src="https://velog.velcdn.com/images/dev-riverkim/post/f797200f-2406-4e32-ad38-9cd953fcb1c9/image.png" alt=""></p>
<pre><code class="language-scss">// grid-columnizer 믹스인 정의
@mixin grid-columnizer($cols: null, $gaps: null) {

    // grid-cols 처리 시작
    // $cols 값이 null인 경우 에러 메시지 출력
    @if $cols == null {
        @error &#39;grid-columnizer 믹스인에서 cols 값을 전달해야 합니다.&#39;;
    }
    // $cols 값이 &#39;none&#39;인 경우 grid-template-columns를 none으로 설정
    @else if $cols == &quot;none&quot; {
        grid-template-columns: none;
    }
    // $cols 값이 단위 없는 숫자인 경우 grid-template-columns를 repeat 함수로 설정
    @else if type-of($cols) == &quot;number&quot; and unitless($cols) {
        grid-template-columns: repeat($cols, minmax(0, 1fr));
    }
    // 위 조건들을 만족하지 않는 나머지 경우에는 $cols 값을 그대로 사용
    else {
        grid-template-columns: $cols;
    }

    // gap 처리 시작
    // $gaps 값이 null이 아닌 경우
    @if $gaps != null {
        // $gaps 값이 list가 아니고 단위가 px 또는 vw인 경우
        @if type-of($gaps) != &quot;list&quot; {
            @if unit($gaps) == &quot;vw&quot; or unit($gaps) == &quot;px&quot; {
                gap: $gaps;
            }
            // 허용되지 않는 단위인 경우 에러 메시지 출력
            @else {
                @error &#39;간격(gaps)에 대한 단위가 잘못되었습니다. px와 vw만 허용됩니다.&#39;;
            }
        }
        // $gaps 값이 두 개의 요소를 갖는 리스트인 경우
        @else if length($gaps) == 2 {
            @if (unit(nth($gaps, 1)) == &quot;vw&quot; or unit(nth($gaps, 1)) == &quot;px&quot;) and (unit(nth($gaps, 2)) == &quot;vw&quot; or unit(nth($gaps, 2)) == &quot;px&quot;) {
                row-gap: nth($gaps, 1);
                column-gap: nth($gaps, 2);
            }
            // 허용되지 않는 단위인 경우 에러 메시지 출력
            @else {
                @error &#39;간격(gaps)에 대한 단위가 잘못되었습니다. px와 vw만 허용됩니다.&#39;;
            }
        }
    }
}

// vw 함수 정의: 특정 픽셀 값을 vw 단위로 변환
@function vw($value) {
    // 1vw의 픽셀 값에 대한 context 설정 (여기서는 750px 기준으로 7.5px)
    $vw-context: (750 * 0.01) * 1px;
    // 입력된 픽셀 값을 vw 단위로 변환하여 반환
    @return ($value/$vw-context) * 1vw;
}



// 사용
.some-element{
    display:grid;
    // 예시
    @include grid-columnizer(2, vw(10px));
    @include grid-columnizer(2, vw(10px) vw(20px));
    @include grid-columnizer(2, 10px);
    @include grid-columnizer(2, 10px 20px);
}</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[[scss]:empty 컨텐츠 여부에 따라 간격이 달라지는 경우]]></title>
            <link>https://velog.io/@dev-riverkim/scssempty-%EC%BB%A8%ED%85%90%EC%B8%A0-%EC%97%AC%EB%B6%80%EC%97%90-%EB%94%B0%EB%9D%BC-%EA%B0%84%EA%B2%A9%EC%9D%B4-%EB%8B%AC%EB%9D%BC%EC%A7%80%EB%8A%94-%EA%B2%BD%EC%9A%B0</link>
            <guid>https://velog.io/@dev-riverkim/scssempty-%EC%BB%A8%ED%85%90%EC%B8%A0-%EC%97%AC%EB%B6%80%EC%97%90-%EB%94%B0%EB%9D%BC-%EA%B0%84%EA%B2%A9%EC%9D%B4-%EB%8B%AC%EB%9D%BC%EC%A7%80%EB%8A%94-%EA%B2%BD%EC%9A%B0</guid>
            <pubDate>Mon, 23 Oct 2023 04:47:16 GMT</pubDate>
            <description><![CDATA[<p>컨텐츠 여부에 따라 간격이 달라지는 경우 사용하면 유용</p>
<p>주의 사항 - 빈 공백이나 줄바꿈이 들어가면 적용되지 않음</p>
<pre><code class="language-html">&lt;!-- 적용가능--&gt;
&lt;div&gt;&lt;/div&gt;
&lt;!-- 적용가능--&gt;
&lt;div&gt;&lt;!--I&#39;m still empty, even with this comment. --&gt;&lt;/div&gt;

&lt;!-- 줄바꿈으로 적용 안됨 --&gt;
&lt;div&gt;

&lt;/div&gt;

&lt;!-- 공백으로 적용 안됨 --&gt;
&lt;div&gt; &lt;/div&gt;</code></pre>
<pre><code class="language-scss">.list {
    display: flex;
    &amp;:not(:empty) {
        margin-top: 12px;
        margin-bottom: 7px;
    }
    ...
    &amp;:not(:empty) + .notice {
        display: block;
        font-size: 12px;
        font-weight: $fw-regular;
        line-height: 1.33;
        color: $color-d01f3c;
    }
}</code></pre>
]]></description>
        </item>
    </channel>
</rss>