⚑

Pipe Function

Pipe Function
어렀움 ν•¨μˆ˜ +40pts

Problem

Write a pipe function that composes functions from left to right.

Examples

Input: pipe(x => x + 1, x => x * 2)(5)
Output: 12
πŸ’‘ (5 + 1) * 2 = 12

Explanation

이 λ¬Έμ œλŠ” **ν•¨μˆ˜ ν•©μ„±(function composition)**의 νŒŒμ΄ν”„ νŒ¨ν„΄μ„ κ΅¬ν˜„ν•˜λŠ” 방법을 ν•™μŠ΅ν•©λ‹ˆλ‹€. ## 핡심 κ°œλ…: νŒŒμ΄ν”„ (Pipe) νŒŒμ΄ν”„λŠ” μ—¬λŸ¬ ν•¨μˆ˜λ₯Ό μ™Όμͺ½μ—μ„œ 였λ₯Έμͺ½μœΌλ‘œ 순차적으둜 μ μš©ν•©λ‹ˆλ‹€. ### μ ‘κ·Ό 방법 ```javascript function pipe(...fns) { return x => fns.reduce((acc, fn) => fn(acc), x); } ``` ### λ™μž‘ 원리 ```javascript pipe(f, g, h)(x) = h(g(f(x))) ``` - f(x)의 κ²°κ³Όλ₯Ό g...

View detailed explanation β†’

Key Concepts

ν•¨μˆ˜ ν•©μ„± pipe reduce ν•¨μˆ˜ν˜• ν”„λ‘œκ·Έλž˜λ°
Time: O(n) Space: O(1)
solution.js
Ctrl + Enter
Run tests to see results here.