Clojure-How to add successive pairs in vector?

前端 未结 3 1922
小鲜肉
小鲜肉 2021-01-19 16:01

Trying to write a recursive function that adds successive pairs in a vector.

[1 2 3 4] => [3 5 7]

Pretty much stuck and this is what I h

3条回答
  •  猫巷女王i
    2021-01-19 16:28

    Partition takes an extra argument specifying how far to step forward between each partition.

    (map #(apply + %) (partition 2 1 [1 2 3 4 5])) =>

    (3 5 7 9)

提交回复
热议问题