Created
July 26, 2011 03:06
-
-
Save tafsiri/1105856 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
(ns day1.core) | |
(defn big [str n] | |
"Returns true if string [str] is longer than [n] | |
false otherwise" | |
(> (count str) n)) | |
;usage | |
(big "hello" 2) | |
(big "hello" 8) | |
(defn collection-type [col] | |
"Returns :list, :map, :vector based on the | |
type of collection [col]" | |
(if (list? col) :list | |
(if (map? col) :map | |
(if (vector? col) :vector | |
"None of the above")))) | |
(defn collection-type-cond [col] | |
"Returns :list, :map, :vector based on the | |
type of collection [col]" | |
(cond | |
(list? col) :list | |
(map? col) :map | |
(vector? col) :vector | |
:else "None of the above")) | |
;usage | |
(collection-type [1,2,3]) | |
(collection-type '(1,2,3)) | |
(collection-type {:one 1, :two 2, :three 3}) | |
(collection-type "huh") | |
(collection-type-cond [1,2,3]) | |
(collection-type-cond '(1,2,3)) | |
(collection-type-cond {:one 1, :two 2, :three 3}) | |
(collection-type-cond "huh") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment