Skip to content

Instantly share code, notes, and snippets.

@dfcarpenter
Created October 1, 2017 23:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dfcarpenter/06f3cd28223061acc7584159dcfcc0fb to your computer and use it in GitHub Desktop.
Save dfcarpenter/06f3cd28223061acc7584159dcfcc0fb to your computer and use it in GitHub Desktop.
converting some JS
getNavStates(indx, length) {
let styles = [];
for (let i=0; i<length; i++) {
if (i < indx) {
styles.push('done');
}
else if (i === indx) {
styles.push('doing');
}
else {
styles.push('todo');
}
}
return { current: indx, styles }
}
(defn getNavStates [idx, length]
(let [styles []]
(loop [x length]
(if (> x length)
{:current idx :styles styles}
(cond
(< x idx) (fn [x]
(assoc styles x "done")
(recur (inc x)))
(= x idx) (fn [x]
(assoc styles x "doing")
(recur (inc x)))
(> x idx) (fn [x]
(assoc styles x "todo")
(recur (inc x))))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment