Sha256: 34743a30f60cff5d6ced7b03ae206450f7bdb568b38e65db6310e84ee519cb18

Contents?: true

Size: 571 Bytes

Versions: 396

Compression:

Stored size: 571 Bytes

Contents

(ns phone-number
  (:require [clojure.string :as str]))

(defn- digits-only
  [input]
  (str/replace input #"\D" ""))

(defn- extract-parts
  [input]
  (if-let [matches (re-find #"^1?(...)(...)(....)$" input)]
    (rest matches)
    ["000" "000" "0000"]))

(defn- parts
  [input]
  (-> input
      digits-only
      extract-parts))

(defn number [input]
  (str/join (parts input)))

(defn area-code [input]
  (first (parts input)))

(defn pretty-print [input]
  (let [[area-code exchange subscriber] (parts input)]
    (str "(" area-code ") " exchange "-" subscriber)))

Version data entries

396 entries across 396 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/clojure/exercises/phone-number/src/example.clj
trackler-2.2.1.179 tracks/clojure/exercises/phone-number/src/example.clj
trackler-2.2.1.178 tracks/clojure/exercises/phone-number/src/example.clj
trackler-2.2.1.177 tracks/clojure/exercises/phone-number/src/example.clj
trackler-2.2.1.176 tracks/clojure/exercises/phone-number/src/example.clj
trackler-2.2.1.175 tracks/clojure/exercises/phone-number/src/example.clj
trackler-2.2.1.174 tracks/clojure/exercises/phone-number/src/example.clj
trackler-2.2.1.173 tracks/clojure/exercises/phone-number/src/example.clj
trackler-2.2.1.172 tracks/clojure/exercises/phone-number/src/example.clj
trackler-2.2.1.171 tracks/clojure/exercises/phone-number/src/example.clj
trackler-2.2.1.170 tracks/clojure/exercises/phone-number/src/example.clj
trackler-2.2.1.169 tracks/clojure/exercises/phone-number/src/example.clj
trackler-2.2.1.167 tracks/clojure/exercises/phone-number/src/example.clj
trackler-2.2.1.166 tracks/clojure/exercises/phone-number/src/example.clj
trackler-2.2.1.165 tracks/clojure/exercises/phone-number/src/example.clj
trackler-2.2.1.164 tracks/clojure/exercises/phone-number/src/example.clj
trackler-2.2.1.163 tracks/clojure/exercises/phone-number/src/example.clj
trackler-2.2.1.162 tracks/clojure/exercises/phone-number/src/example.clj
trackler-2.2.1.161 tracks/clojure/exercises/phone-number/src/example.clj
trackler-2.2.1.160 tracks/clojure/exercises/phone-number/src/example.clj