4clojure 题解 Nth Element

作者: admin 日期: 2017-12-27 14:53:21 人气: - 评论: 0

模拟nth函数


Write a function which returns the Nth element from a sequence.

test not run
(= (__ '(4 5 6 7) 2) 6)

test not run

(= (__ [:a :b :c] 0) :a)
test not run
(= (__ [1 2 3 4] 1) 2)
test not run

(= (__ '([1 2] [3 4] [5 6]) 2) [5 6])










用递归试了下可以通过

(fn d [seq x]
(if (> x 0)
(d (rest seq) (dec x))
(first seq)))


相关内容

发表评论
更多 网友评论0 条评论)
暂无评论

Copyright © 2012-2014 我的代码板 Inc. 保留所有权利。

页面耗时0.0287秒, 内存占用1.83 MB, 访问数据库13次

闽ICP备15009223号-1