Skip to content

Commit

Permalink
[Docs] 20240227 코딩테스트
Browse files Browse the repository at this point in the history
  • Loading branch information
owni14 committed Feb 26, 2024
1 parent 4fc8fc8 commit aea6153
Show file tree
Hide file tree
Showing 14 changed files with 900 additions and 30 deletions.
7 changes: 4 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -236,15 +236,15 @@ GEM
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
mercenary (0.3.6)
mini_portile2 (2.8.5)
minima (2.5.1)
jekyll (>= 3.5, < 5.0)
jekyll-feed (~> 0.9)
jekyll-seo-tag (~> 2.1)
minitest (5.15.0)
multipart-post (2.1.1)
nokogiri (1.13.3-arm64-darwin)
racc (~> 1.4)
nokogiri (1.13.3-x64-mingw32)
nokogiri (1.13.3)
mini_portile2 (~> 2.8.0)
racc (~> 1.4)
octokit (4.22.0)
faraday (>= 0.9)
Expand Down Expand Up @@ -292,6 +292,7 @@ GEM
PLATFORMS
arm64-darwin-21
arm64-darwin-22
arm64-darwin-23
x64-mingw32

DEPENDENCIES
Expand Down
42 changes: 15 additions & 27 deletions _layouts/post.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,25 @@
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# GNU General Public License for more de[tai]ls.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

layout: base
---

{% assign version = jekyll.version | split:'.' %}
{% assign major = version[0] | plus:0 %}
{% assign minor = version[1] | plus:0 %}
{% assign patch = version[2] | plus:0 %}

{% include_cached components/post.html post=page no_link_title=true no_excerpt=true hide_image=page.hide_image hide_description=page.hide_description %}

{% include components/dingbat.html %}

{% assign addons = page.addons | default:site.hydejack.post_addons %}
{% unless addons %}{% assign addons = "about,newsletter,related,random" | split:"," %}{% endunless %}
{% for addon in addons %}
{% case addon %}
{% when 'about' %}
{% include_cached components/about.html author=page.author %}
{% when 'newsletter' %}
{% include if-non-null try="pro/newsletter.html" %}
{% when 'related' %}
{% include if-non-null try="pro/related-posts.html" fallback="components/related-posts.html" %}
{% when 'random' %}
{% include if-non-null try="pro/random-posts.html" %}
{% when 'comments' %}
{% include body/comments.html %}
{% else %}
{% endcase %}
{% endfor %}
{% assign version = jekyll.version | split:'.' %} {% assign major = version[0] |
plus:0 %} {% assign minor = version[1] | plus:0 %} {% assign patch = version[2]
| plus:0 %} {% include_cached components/post.html post=page no_link_title=true
no_excerpt=true hide_image=page.hide_image
hide_description=page.hide_description %} {% include components/dingbat.html %}
{% assign addons = page.addons | default:site.hydejack.post_addons %} {% unless
addons %}{% assign addons = "about,newsletter,related,random" | split:"," %}{%
endunless %} {% for addon in addons %} {% case addon %} {% when 'about' %} {%
include_cached components/about.html author=page.author %} {% when 'newsletter'
%} {% include if-non-null try="pro/newsletter.html" %} {% when 'related' %} {%
include if-non-null try="pro/related-posts.html"
fallback="components/related-posts.html" %} {% when 'random' %} {% include
if-non-null try="pro/random-posts.html" %} {% when 'comments' %} {% include
body/comments.html %} {% else %} {% endcase %} {% endfor %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
---
layout: post
title: '[프로그래머스 / lv0] 이어 붙인 수'
subtitle: '[프로그래머스 / lv0] 이어 붙인 수'
category: dev
tag: algorithm
image:
path: /assets/img/algorithm.png
---

<!-- prettier-ignore -->
* this ordered seed list will be replaced by the toc
{:toc}

## 문제

---

### **문제 설명**

---

정수가 담긴 리스트 `num_list`가 주어집니다. `num_list`의 홀수만 순서대로 이어 붙인 수와 짝수만 순서대로 이어 붙인 수의 합을 return하도록 solution 함수를 완성해주세요.

### 제한사항

---

- 2 ≤ `num_list`의 길이 ≤ 10
- 1 ≤ `num_list`의 원소 ≤ 9
- `num_list`에는 적어도 한 개씩의 짝수와 홀수가 있습니다.

### 입출력 예

---

| num_list | result |
| --------------- | ------ |
| [3, 4, 5, 2, 1] | 393 |
| [5, 7, 8, 3] | 581 |

### 입출력 예 설명

---

입출력 예 #1

- 홀수만 이어 붙인 수는 351이고 짝수만 이어 붙인 수는 42입니다. 두 수의 합은 393입니다.

입출력 예 #2

- 홀수만 이어 붙인 수는 573이고 짝수만 이어 붙인 수는 8입니다. 두 수의 합은 581입니다.

### 풀이

---

```jsx
function solution(num_list) {
const { even, odd } = num_list.reduce(
(acc, cur) => {
let curEven = '';
let curOdd = '';
if (cur % 2 === 0) {
curEven = cur.toString();
} else {
curOdd = cur.toString();
}
return { even: acc.even + curEven, odd: acc.odd + curOdd };
},
{ even: '', odd: '' }
);

const answer = Number(even) + Number(odd);
return answer;
}
```

### 느낀점

---

reduce를 사용해 구조분해 할당으로 짝수, 홀수를 받아서 사용하면 좀 더 가독성이 높지 않을까라는 생각을하여 해당 방법으로 코드를 작성했다.
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
---
layout: post
title: '[프로그래머스 / lv0] flag에 따라 다른 값 반환하기'
subtitle: '[프로그래머스 / lv0] flag에 따라 다른 값 반환하기'
category: dev
tag: algorithm
image:
path: /assets/img/algorithm.png
---

<!-- prettier-ignore -->
* this ordered seed list will be replaced by the toc
{:toc}

## 문제

---

### **문제 설명**

---

두 정수 `a``b`와 boolean 변수 `flag`가 매개변수로 주어질 때, `flag`가 true면 `a` + `b`를 false면 `a` - `b`를 return 하는 solution 함수를 작성해 주세요.

### 제한사항

---

- 1,000 ≤ `a``b` ≤ 1,000

### 입출력 예

---

| a | b | flag | result |
| --- | --- | ----- | ------ |
| -4 | 7 | true | 3 |
| -4 | 7 | false | -11 |

### 입출력 예

---

입출력 예 #1

- 예제 1번에서 `flag`가 true이므로 `a` + `b` = (-4) + 7 = 3을 return 합니다.

입출력 예 #2

- 예제 2번에서 `flag`가 false이므로 `a` - `b` = (-4) - 7 = -11을 return 합니다.

### 풀이

---

```jsx
function solution(a, b, flag) {
const sum = a + b;
const sub = a - b;
return flag ? sum : sub;
}
```

### 느낀점

---

바로 삼항연산자를쓰고 계산식을 변수 선언안하고 사용할 수 있었지만 나는 그래도 변수로 빼서 하는게 가독성이 좋다고 생각해서 따로 빼서 삼항연산자를 썼다.
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
---
layout: post
title: '[프로그래머스 / lv0] n번째 원소까지'
subtitle: '[프로그래머스 / lv0] n번째 원소까지'
category: dev
tag: algorithm
image:
path: /assets/img/algorithm.png
---

<!-- prettier-ignore -->
* this ordered seed list will be replaced by the toc
{:toc}

## 문제

---

### **문제 설명**

---

정수 리스트 `num_list`와 정수 `n`이 주어질 때, `num_list`의 첫 번째 원소부터 `n` 번째 원소까지의 모든 원소를 담은 리스트를 return하도록 solution 함수를 완성해주세요.

### 제한사항

- 2 ≤ `num_list`의 길이 ≤ 30
- 1 ≤ `num_list`의 원소 ≤ 9
- 1 ≤ `n` ≤ `num_list`의 길이 \_\_\_

### 입출력 예

---

| num_list | n | result |
| --------------- | --- | --------- |
| [2, 1, 6] | 1 | [2] |
| [5, 2, 1, 7, 5] | 3 | [5, 2, 1] |

### 입출력 예 설명

---

입출력 예 #1

- [2, 1, 6]의 첫 번째 원소부터 첫 번째 원소까지의 모든 원소는 [2]입니다.

입출력 예 #2

- [5, 2, 1, 7, 5]의 첫 번째 원소부터 세 번째 원소까지의 모든 원소는 [5, 2, 1]입니다.

### 풀이

---

```jsx
function solution(num_list, n) {
const answer = num_list.reduce((acc, cur, idx) => {
if (idx < n) {
return [...acc, cur];
}
return acc;
}, []);
return answer;
}
```

### 느낀점

---

다른 사람의 풀이를 보니 slice를 사용하던데 나는 reduce를 사용해서 너무 빙빙 돌아서 푼게 아닌가라는 생각이 든다.
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---
layout: post
title: '[프로그래머스 / lv0] 대문자로 바꾸기'
subtitle: '[프로그래머스 / lv0] 대문자로 바꾸기'
category: dev
tag: algorithm
image:
path: /assets/img/algorithm.png
---

<!-- prettier-ignore -->
* this ordered seed list will be replaced by the toc
{:toc}

## 문제

---

### **문제 설명**

---

알파벳으로 이루어진 문자열 `myString`이 주어집니다. 모든 알파벳을 대문자로 변환하여 return 하는 solution 함수를 완성해 주세요.

### 제한사항

---

- 1 ≤ `myString`의 길이 ≤ 100,000
- `myString`은 알파벳으로 이루어진 문자열입니다.

### 입출력 예

---

### 풀이

---

```jsx
function solution(myString) {
return myString.toUpperCase();
}
```

### 느낀점

---

현업에서 toUpperCase()나 toLowerCase()를 종종 사용하였기 때문에 문제를 보는 순간 방법이 바로 떠올랐다.
Loading

0 comments on commit aea6153

Please sign in to comment.