4clojure 题解 Map Construction

把两个序列合并成一个map,不允许使用zipmapWrite a function which takes a vector of keys and a vector of values and constructs a map from them.(= (__ [:a :b :c] [1 2 3]) {:a 1, :b 2, :c 3})(= (__ [1 2 3 4] ["one" "two" "three"]
作者:admin发表于:2017-12-29 15:21:11

4clojure 题解 Advanced Destructuring

高级解构(let [[a b & c :as d] [1 2 3 4 5]] [a b c d])=> [1 2 (3 4 5) [1 2 3 4 5]]& 符号后面跟的符号c表示取除 a 和 b 除外的剩余部分:as 符号后面跟的 d 表示取原始数据
作者:admin发表于:2017-12-29 15:20:10

4clojure 题解 Split a sequence

根据参数切割一个序列,不允许使用split-atWrite a function which will split a sequence into two parts.(= (__ 3 [1 2 3 4 5 6]) [[1 2 3] [4 5 6]])(= (__ 1 [:a :b :c :d]) [[:a] [:b :c :d]])(= (__ 2 [[1 2] [3 4] [5 6]]) [[[1 2] [3 4]] [[5 6]]])解答(fn [n coll]
作者:admin发表于:2017-12-29 15:02:56

4clojure 题解 Drop Every Nth Item

编写一个函数美隔接收一个序列coll和整数n每隔n个元素就删除coll中的一个元素Write a function which drops every Nth item from a sequence.(= (__ [1 2 3 4 5 6 7 8] 3) [1 2 4 5 7 8])(= (__ [:a :b :c :d :e :f] 2) [:a :c :e])(= (__ [1 2 3 4 5 6] 4) [1 2 3 5 6])(fn
作者:admin发表于:2017-12-29 14:55:41

4clojure 题解 Flatten a Sequence

扁平化一个序列,但是不允许使用flattenWrite a function which flattens a sequence.(= (__ '((1 2) 3 [4 [5 6]])) '(1 2 3 4 5 6))(= (__ ["a" ["b"] "c"]) '("a" "b" "c"))(= (__ '((((:a))
作者:admin发表于:2017-12-28 10:47:20

clojure complement函数

complement函数就是返回一个与目标函数接收同样参数但是返回结果相反的函数( (fn [x] (filter (complement sequential?) (rest (tree-seq sequential? seq x))) ) '((1 2) 3 [4 [5 6]]))=> (1 2 3 4 5 6)等价于( (fn [x] (filter #(not (sequential? %)) (rest (tree-
作者:admin发表于:2017-12-28 10:33:35

4clojure 题解 Interleave Two Seqs

交织两个序列,不得使用interleave操作Write a function which takes two sequences and returns the first item from each, then the second item from each, then the third, etc.(= (__ [1 2 3] [:a :b :c]) '(1 :a 2 :b 3 :c))(= (__ [1 2] [3 4 5 6]) '(1 3 2 4
作者:admin发表于:2017-12-28 10:13:48

4clojure 题解 Compress a Sequence

去除字符串中连续重复的部分Write a function which removes consecutive duplicates from a sequence.(= (apply str (__ "Leeeeeerrroyyy")) "Leroy")(= (__ [1 1 2 3 3 2 2 3]) '(1 2 3 2 3))(= (__ [[1 2] [1 2] [3 4] [1 2]]) '([1 2] [3 4]
作者:admin发表于:2017-12-28 09:39:20

clojure some函数

some函数可以从集合中找到满足条件的第一个数据some支持接收一个集合作为参数(some #{2 7 6} [5 6 7 8])=> 6也支持接收一个函数作为条件(some #(when (even? %) %) [5 6 7 8])=> 6其实在clojure里面集合也是一个函数,filter和map等操作同样支持集合作为参数(filter #{
作者:admin发表于:2017-12-27 19:22:44

4clojure 题解 Duplicate a Sequence

输出重复的序列Write a function which duplicates each element of a sequence.(= (__ [1 2 3]) '(1 1 2 2 3 3))(= (__ [:a :a :b :b]) '(:a :a :a :a :b :b :b :b))(= (__ [[1 2] [3 4]]) '([1 2] [1 2] [3 4] [3 4]))(= (__ [[1 2] [3 4]]) '([1 2] [1 2]
作者:admin发表于:2017-12-27 19:08:41
33«1234»

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

页面耗时0.0252秒, 内存占用1.9 MB, 访问数据库11次

闽ICP备15009223号-1