4clojure 题解 Count a Sequence

作者: admin 日期: 2017-12-27 15:01:00 人气: - 评论: 0

统计集合元素的数量不允许使用count操作

Write a function which returns the total number of elements in a sequence.

test not run
(= (__ '(1 2 3 3 1)) 5)
test not run
(= (__ "Hello World") 11)
test not run
(= (__ [[1 2] [3 4] [5 6]]) 3)
test not run
(= (__ '(13)) 1)
test not run
(= (__ '(:a :b :c)) 3)













用递归搞定

(fn d [seq]
(if (empty? seq)
0
    (+ (d (rest seq)) 1)))


相关内容

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

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

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

闽ICP备15009223号-1