交织两个向量,其中长度相差一 [英] Interleave two vectors where the length differs by one
本文介绍了交织两个向量,其中长度相差一的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用 n + 1
和 n
成员交叉两个向量的最简单方法是什么?
What is the simplest way to interleave two vectors with n+1
and n
members?
(def a [:a :c :e])
(def b [:b :d])
(interleave a b ); truncates to shortest list
[:a :b :c :d]
;what I would like.
(interleave-until-nil a b)
[:a :b :c :d :e]
推荐答案
不包括第一个,交替其余的参数颠倒。
Cons the first, interleave the rest with arguments reversed.
(cons (first a) (interleave b (rest a)))
;=> (:a :b :c :d :e)
这篇关于交织两个向量,其中长度相差一的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文