Skip to content

Instantly share code, notes, and snippets.

@PEZ
Last active April 25, 2024 18:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PEZ/e9ba5a581234d1bddbae5caa2e51aa51 to your computer and use it in GitHub Desktop.
Save PEZ/e9ba5a581234d1bddbae5caa2e51aa51 to your computer and use it in GitHub Desktop.
Map Construction – Rich 4Clojure Problem 61 – See: https://github.com/PEZ/rich4clojure
(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
Copy link

chenj7 commented Sep 8, 2021

(def __ #(apply hash-map (interleave % %2)))

@StanTheBear
Copy link

(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)))

@antoniofunnel
Copy link

  (defn __ [k v]
    (reduce conj (map (fn [a b] {a b}) k v)))
  )

@natef-GuruTech
Copy link

natef-GuruTech commented Apr 25, 2024

(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