Fork me on GitHub
#clojurescript
<
2020-07-05
>
metehan07:07:22

clojurescript doesn't run this (_re-matches_ #"^\S{1,}\/\S{1,}$" "users/232") it says browser.cljs:220 repl/invoke error SyntaxError: Invalid regular expression flags this regex works fine on why I can't run same regex on cljs?

p-himik08:07:06

The error is misleading. Drop the \ before the /.

p-himik08:07:18

So it becomes #"^\S{1,}/\S{1,}$".

metehan08:07:25

thank you it works now. why this needed to be removed how can I learn more about this issue

p-himik08:07:09

/ is a regular character, you don't need to escape it in general. You only need to escape it in JavaScript because it uses / to denote the start and the end of a regexp.

metehan08:07:14

ah i see thank you very much

Jacob Emcken11:07:24

I want to swap axis in a 2-dimensional vector:

[["A" "2"]
 ["B" "7"]
 ["C" "4"]]

[["A" "B" "C"]
 ["2" "7" "4"]]

Jacob Emcken11:07:31

All my tries so far become very hairy very fast... I'm certain that somebody else have already solved this (and very likely much better than I can)?

p-himik11:07:23

(defn pivot [t]
  (mapv (fn [idx]
          (mapv #(nth % idx) t))
        (range (count (first t)))))

Jacob Emcken11:07:07

nice thanks 👍

Jacob Emcken11:07:21

much better than my loop-recur 😆

yogidevbear11:07:02

Not in front of my laptop, but another option might be something like:

(partition
  (count coll)
  (apply interleave coll)

Jan K12:07:37

(defn transpose [m] 
  (apply mapv vector m))

👍 15
12
clj 6
noisesmith14:07:28

the version that @UCPGSBNQ4 shows is one of the classic examples of clojure's elegance

clj 6