Skip to content

06 - Advanced Functions #41

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ importance: 5

---

# Set and decrease for counter
# 카운터를 설정하고 감소시키기

Modify the code of `makeCounter()` so that the counter can also decrease and set the number:
`makeCounter()` 함수를 수정해서 카운터가 숫자를 감소시키고 설정하게 해보세요.

- `counter()` should return the next number (as before).
- `counter.set(value)` should set the `count` to `value`.
- `counter.decrease()` should decrease the `count` by 1.
- `counter()` 다음 숫자를 반환합니다. (이전의 것처럼)
- `counter.set(value)` `count` `value` 로 설정합니다.
- `counter.decrease()` `count`를 1 감소시킵니다.

See the sandbox code for the complete usage example.
샌드박스의 코드를 완성된 예제로 참고하세요.

P.S. You can use either a closure or the function property to keep the current count. Or write both variants.
P.S. 클로져나 함수프로퍼티를 사용해서 현재 count 값을 유지해도 됩니다. 또는 두 방법을 모두 사용해도 됩니다.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ importance: 2

---

# Sum with an arbitrary amount of brackets
# 정해지지않은 괄호의 양을 합산하기

Write function `sum` that would work like this:
다음과 같이 작동하는 `sum` 함수를 작성해보세요.

```js
sum(1)(2) == 3; // 1 + 2
Expand All @@ -14,4 +14,4 @@ sum(6)(-1)(-2)(-3) == 0
sum(0)(1)(2)(3)(4)(5) == 15
```

P.S. Hint: you may need to setup custom object to primitive conversion for your function.
P.S. 힌트: 아마도 특수 객체(custom object)를 활용해서 원시값 변환에 사용하세요.
Loading