this question has answer here:
i came across snippet of code in book of clojure. can please explain me how contains? works?
(contains? [1 2 3] 3) ;= false (contains? [1 2 3] 2) ;= true (contains? [1 2 3] 0) ;= true
just @ documentation:
contains?
(contains? coll key)
returns true if key present in given collection, otherwise returns false. note numerically indexed collections vectors , java arrays, tests if numeric key within range of indexes. 'contains?' operates constant or logarithmic time; not perform linear search value. see 'some'.
so, in example, (contains? [1 2 3] 3) returns false because collection [1 2 3] not contain item @ index 3 (that means (get [1 2 3] 3) return nil).
Comments
Post a Comment