-
-
Save wvdlaan/081d94f7dd288b73cc6f9c3ab97dda58 to your computer and use it in GitHub Desktop.
Berlin Clock kata as implemented at the Amsterdam Clojurians cljs dojo, meetup #80
This file contains hidden or 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 berlin-clock.core | |
(:require | |
[sablono.core :as sab :include-macros true]) | |
(:require-macros | |
[devcards.core :as dc :refer [defcard deftest]])) | |
(enable-console-print!) | |
(defn get-clock-data | |
[hh mm ss] | |
[(quot hh 5) | |
(mod hh 5) | |
(quot mm 5) | |
(mod mm 5) | |
(mod ss 2)]) | |
(defcard ms | |
(let [dt (js/Date.) | |
hh (.getHours dt) | |
mm (.getMinutes dt) | |
ss (.getSeconds dt)] | |
(get-clock-data hh mm ss))) | |
(defcard ms2 | |
(let [[r1 r2 r3 r4 r5] (get-clock-data 4 59 0)] | |
(sab/html | |
[:div | |
[:div {:className (if (zero? r5) "top-button-on" "top-button-off")}] | |
[:p] | |
(map (fn [i] | |
[:div {:className "top-button-on" :style {:background-color (if (< i r1) "red" "black")}}]) | |
(range 4))]))) | |
(defcard ms3 | |
(let [[r1 r2 r3 r4 r5] (get-clock-data 5 59 1)] | |
(sab/html | |
[:div | |
[:div {:className (if (zero? r5) "top-button-on" "top-button-off")}] | |
[:p] | |
(map (fn [i] | |
[:div {:className "top-button-on" :style {:background-color (if (< i r1) "red" "black")}}]) | |
(range 4))]))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment