Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; Write a function which takes a sequence consisting of items with different types and splits them up into a set of homogeneous sub-sequences. The internal order of each sub-sequence should be maintained, but the sub-sequences themselves can be returned in any order (this is why 'set' is used in the test cases).
- (fn organize-v2
- [some-seq]
- (map
- (fn [item]
- (into [] (reverse item)))
- (vals
- (loop [index 0
- new-seq {}]
- (if (< index (count some-seq))
- (recur
- (inc index)
- (update
- new-seq
- (type (some-seq index))
- (fn [item]
- (or (= item []) (conj item (some-seq index))))))
- new-seq)))))
- (= (set (organize-v2 [1 :a 2 :b 3 :c])) #{[1 2 3] [:a :b :c]})
- (= (set (organize-v2 [:a "foo" "bar" :b])) #{[:a :b] ["foo" "bar"]})
- (= (set (organize-v2 [[1 2] :a [3 4] 5 6 :b])) #{[[1 2] [3 4]] [:a :b] [5 6]})
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement