2 ms·
const y = h(g(f(x))) const y = x |> f(%) |> g(%) |> h(%) It get's better with const y = g * k + j / w * d - 453368423 |> (x) => { 4566 * x
by ReleaseCandidat 5y ago
const y = h(g(f(x)))
const y = x |> f(%) |> g(%) |> h(%)
It get's better with
const y =
g * k + j / w * d - 453368423
|> (x) => { 4566 * x + 46832 - x * x + 1 / x}(%)
|> (x) => { x / 4653 + 843 * x *x }(%)
|> (x) => { 486543 - x + x * x }(%)
The question is if you often do things like that, though ;)
- nmcfarl 5y agoThe example that resonates with me is when the functions have multiple parameters: const y = h(1, g(f("world", x, 3 ),true)) const y = x |> f("world", x, 3) |> g(%, true) |> h(1, %)
- jlokier 5y agoMore readable, imho: const a = g * k + j / w * d - 453368423 const b = 4566 * a + 46832 - a * a + 1 / a const c = b / 4653 + 843 * b * b const y = 486543 - c + c * c
- ReleaseCandidat 5y agoI actually do prefer this too. And when using it for arrays, I'd prefer const r = [a, b, c] .map((e) => 2 * e*e) .filter((e) => e >= 0) .reduce((acc, e) => acc + e) to the new piped version.