Last active
April 25, 2024 18:50
-
-
Save PEZ/e9ba5a581234d1bddbae5caa2e51aa51 to your computer and use it in GitHub Desktop.
Map Construction – Rich 4Clojure Problem 61 – See: https://github.com/PEZ/rich4clojure
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
(ns rich4clojure.easy.problem-061 | |
(:require [hyperfiddle.rcf :refer [tests]])) | |
;; = Map Construction = | |
;; By 4Clojure user: dbyrne | |
;; Difficulty: Easy | |
;; Tags: [core-functions] | |
;; | |
;; Write a function which takes a vector of keys and a | |
;; vector of values and constructs a map from them. | |
(def restricted [zipmap]) | |
(def __ :tests-will-fail) | |
(comment | |
) | |
(tests | |
(__ [:a :b :c] [1 2 3]) := {:a 1, :b 2, :c 3} | |
(__ [1 2 3 4] ["one" "two" "three"]) := {1 "one", 2 "two", 3 "three"} | |
(__ [:foo :bar] ["foo" "bar" "baz"]) := {:foo "foo", :bar "bar"}) | |
;; To participate, fork: | |
;; https://github.com/PEZ/rich4clojure | |
;; Post your solution below, please! |
chenj7
commented
Sep 8, 2021
(fn [key-vec val-vec] "from vector of keys and vector of values make map (drop any not paired)" (apply assoc {} (interleave key-vec val-vec)))
(defn __ [k v]
(reduce conj (map (fn [a b] {a b}) k v)))
)
(def __ (fn [ks vs]
(into {} (map (fn [k v] {k v})
ks vs))))
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment