依據給予的次數重複字串
Write a function called repeat_str which repeats the given string src
exactly count
times.
repeatStr(6, "I") // "IIIIII"
repeatStr(5, "Hello") // "HelloHelloHelloHelloHello"
(ns clojure.string-repeat)
(defn repeat-str [n strng]
(apply str (repeat n strng)))
(repeat 2 "I") ;; ("I" "I")
(str "I" "I") ;; "II"
(apply str "I" "I") ;; "II"
(str (repeat 2 "I")) ;; "(\"I\" \"I\")"
;; str is common to apply to an existing collection, compare with the previous example
(apply str (repeat 2 "I")) ;; "II"
;; (join separator coll) Returns a string of all elements in coll, as returned by (seq coll), separated by an optional separator.
(ns clojure.string-repeat)
(defn repeat-str [n str]
(clojure.string/join (repeat n str)))