Last active
January 20, 2023 01:05
-
-
Save PEZ/efa257369fd08ba1dcef6bec34d04ede to your computer and use it in GitHub Desktop.
Indexing Sequences – Rich 4Clojure Problem 157 – 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-157 | |
(:require [hyperfiddle.rcf :refer [tests]])) | |
;; = Indexing Sequences = | |
;; By 4Clojure user: jaycfields | |
;; Difficulty: Easy | |
;; Tags: [seqs] | |
;; | |
;; Transform a sequence into a sequence of pairs | |
;; containing the original elements along with their | |
;; index. | |
(def __ :tests-will-fail) | |
(comment | |
) | |
(tests | |
(__ [:a :b :c]) := [[:a 0] [:b 1] [:c 2]] | |
(__ [0 1 3]) := '((0 0) (1 1) (3 2)) | |
(__ [[:foo] {:bar :baz}]) := [[[:foo] 0] [{:bar :baz} 1]]) | |
;; To participate, fork: | |
;; https://github.com/PEZ/rich4clojure | |
;; Post your solution below, please! |
blogscot
commented
Aug 20, 2022
(def __ (fn [seq-in]
(partition 2 (interleave seq-in (iterate inc 0)))))
Shush as blogscot wrote - range rather than (iterate inc 0) doh!
(def __ (fn [seq-in]
(partition 2 (interleave seq-in (range)))))
(defn pairs* [coll] (map (fn [a b] [a b]) coll (range)))
Shush as blogscot wrote - range rather than (iterate inc 0) doh!
(def __ (fn [seq-in]
(partition 2 (interleave seq-in (range)))))
(def __ (fn [s]
(map vector s (range))))
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment