Skip to content

Commit

Permalink
챕터 12 (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
hyesungoh authored May 24, 2024
1 parent fa0466f commit b494773
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions 챕터_12/오혜성.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# 함수형 반복

## Map

```js
function map(arr, f) {
const newArr = []
for (const val of arr) {
newArr.push(f(val))
}
return newArr
}
```

## Filter

```js
function filter(arr, f) {
const newArr = []
for (const val of arr) {
if (f(val)) newArr.push(val)
}
return newArr
}
```

## Reduce

```js
function reduce(arr, init, f) {
let acc = init
for (const val of arr) {
acc = f(acc, val)
}
return acc
}
```

* fold 라는 이름으로도 사용됨
+ foldLeft, foldRight 같이 탐색 방향에 따른 버전도 있음

0 comments on commit b494773

Please sign in to comment.