Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

freqs

  • Loading branch information...
commit 3b813abaddcaae14e61ba73d619840eabd5b4a50 1 parent 9ce34f7
@alandipert alandipert authored
View
3  src/cljs/tailrecursion/javelin-demos/form_validation.cljs
@@ -8,7 +8,8 @@
(ns tailrecursion.javelin-demos.form-validation
(:require [tailrecursion.javelin-demos.dom :refer [input-to by-id validator]]
- [clojure.browser.event :as event])
+ [clojure.browser.event :as event]
+ tailrecursion.javelin)
(:require-macros [tailrecursion.javelin.macros :refer [cell]]))
(def preds
View
15 src/cljs/tailrecursion/javelin-demos/frequencies.cljs
@@ -61,7 +61,7 @@
(let [;; user input
rand-max (form-cell "#rand-max" :type :int, :default 10, :triggers #{"change"})
slider (form-cell "#ms" :type :int, :default 500)
- interval (cell (if (neg? slider) slider (- 1000 slider)))
+ interval (cell (if (neg? slider) 0 (- 1001 slider)))
;; stem cell
freqs (cell '(priority-map (rand-int @rand-max) 1))
@@ -78,15 +78,18 @@
least-frequent (cell (key (peek freqs)))
n-distinct (cell (count freqs))]
+ (cell
+ (.log js/console (pr-str (reduce + (vals freqs)))))
+
;; add random numbers to stem cell
((fn self []
- (swap! freqs update-in [(rand-int @rand-max)] (fnil inc 0))
- (.setTimeout js/window self @interval)))
+ (let [sleep @interval]
+ (if (pos? sleep)
+ (swap! freqs update-in [(rand-int @rand-max)] (fnil inc 0)))
+ (.setTimeout js/window self sleep))))
;; display
- (cell (html! "#status" "%s (interval is %s milliseconds)"
- (if (neg? interval) "Stopped" "Running")
- interval))
+ (cell (html! "#status" "%s" (if (zero? interval) "Stopped" "Running")))
(cell (html! "#most-frequent" "%s" most-frequent))
(cell (html! "#n-seen" "%s" n-seen))
(cell (html! "#percent-even" "%s%" %-even))
View
5 src/cljs/tailrecursion/javelin-demos/lettercount.cljs
@@ -7,7 +7,8 @@
; You must not remove this notice, or any other, from this software.
(ns tailrecursion.javelin-demos.lettercount
- (:require [tailrecursion.javelin-demos.dom :refer [form-cell by-id html!]])
+ (:require [tailrecursion.javelin-demos.dom :refer [form-cell by-id html!]]
+ tailrecursion.javelin)
(:require-macros [tailrecursion.javelin.macros :refer [cell]]))
(defn ^:export start []
@@ -15,4 +16,4 @@
(let [text (form-cell "#text")
length (cell (count text))]
(.focus (by-id "#text"))
- (cell (html! "#count" "Length: %s" length))))
+ (cell (html! "#count" "Length: %s" length))))
Please sign in to comment.
Something went wrong with that request. Please try again.