I have a map like this
(def invoice
{:productId ["001" "002" "003" "004" "005" "006" "007" "008" "009" "010"],
:price ["50" "60" "70" "50" "40" "45" "55" "90" "50" "70"],
:quantity ["0" "0" "1" "2" "0" "0" "0" "0" "0" "1"]})
how can i filter so it only show product id where the quantity is 1 or more ?
i already tried to make like this
(filter (> (invoice :quantity %) 1) (map list (invoice :price) (invoice :quantity) (invoice :productid))
but it doesn't work
first step would be construct a pair of Product ID and quantity:
(map vector (invoice :quantity) (invoice :productId))
;; ["0" "001"] .... first element would be quantity and second is productiID
second step would be filter out which quantity is greater than 0, here I use (Integer. xx) to conver the quantity to a number.
(filter #(> (Integer. (first %)) 0) (map vector (invoice :quantity) (invoice :productId)))
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句