小编ptm*_*der的帖子

函数组合 - 多次循环数组进行多个操作不是效率低下吗?

我试图理解函数式编程的概念和基础知识。我不会死守 Haskell、Clojure 或 Scala。相反,我使用 JavaScript。

因此,如果我理解正确的话,函数式编程背后的想法是使用纯函数编写软件应用程序 - 它负责处理应用程序中的单一职责/功能,而不会产生任何副作用。

组合以这样一种方式进行:一个函数的输出通过管道作为另一个函数的输入(根据逻辑)。

我编写了两个分别用于加倍和递增的函数,它们以整数作为参数。接下来是一个实用函数,它组成了作为参数传入的函数。

{
    // doubles the input
    const double = x => x * 2

    // increments the input
    const increment = x => x + 1

    // composes the functions
    const compose = (...fns) => x => fns.reduceRight((x, f) => f(x), x)

    // input of interest
    const arr = [2,3,4,5,6]

    // composed function
    const doubleAndIncrement = compose(increment, double)

    // only doubled
    console.log(arr.map(double))

    // only incremented
    console.log(arr.map(increment))

    // double and increment
    console.log(arr.map(doubleAndIncrement)) …
Run Code Online (Sandbox Code Playgroud)

javascript functional-programming function node.js ecmascript-6

3
推荐指数
1
解决办法
510
查看次数

SVG 路径动画不符合预期

月亮需要沿着与 id 为trajectory围绕行星的路径相同的路径移动。但它是随机移动的(好像在庆祝 4/20)。

请找到随附的代码。

.moon {
  offset-path: path('m159.39 54.867a71.83 20.37 0 0 1-71.83 20.37 71.83 20.37 0 0 1-71.83-20.37 71.83 20.37 0 0 1 71.83-20.37 71.83 20.37 0 0 1 71.83 20.37z');
  animation: revolve 10s 1s infinite ease-in-out forwards;
}

@keyframes revolve {
  from {
    offset-distance: 0%;
  }

  to {
    offset-distance: 100%;
  }
}
Run Code Online (Sandbox Code Playgroud)
<svg width="169.31" height="115.66" viewBox="0 0 169.31 115.66">
  <circle cx="87.56" cy="54.867" r="45.855" fill="#ff4141" />
  <circle class="moon" cx="18.051" cy="54.867" r="8.092" fill="#ff9900" />
  <path
        id="trajectory"
        d="m18.051 …
Run Code Online (Sandbox Code Playgroud)

html css svg css-animations

3
推荐指数
1
解决办法
50
查看次数

AWS DynamoDB - 免费套餐混乱

根据此页面,DynamoDB对于 25 RCU 和 25 WCU 以及 25GB 存储始终免费。

但是,在表的容量选项卡中,它显示 10 个 RCU 和 10 个 WCU 的估计成本为 5.81 美元/月。 DynamoDB 表的容量选项卡显示 10 个 RCU 和 10 个 WCU 的估计成本

我是否会被收取这笔费用?

amazon-web-services amazon-dynamodb

3
推荐指数
1
解决办法
1480
查看次数