Created
February 5, 2014 13:34
-
-
Save edtsech/8823692 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn split-by | |
"Create from sequence (l) sequence of sequences with specified number of elemenets (c) | |
Example: | |
(split-by 2 [1 2 3 4 5 6 7]) | |
=> '((1 2) (3 4) (5 6) (7))" | |
[c l] | |
(if (seq l) | |
(cons (take c l) (split-by c (drop c l))))) | |
(defn split-into-chunks | |
"Split sequence (l) into specified number of chunks (c) | |
Example: | |
(split-into-chunks 3 [1 2 3 4 5 6 7]) | |
=> '((1 2 3) (4 5 6) (7))" | |
[c l] | |
(split-by (inc (int (/ (count l) c))) l)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment