Skip to content

Instantly share code, notes, and snippets.

@ohAitch
Created July 11, 2015 19:39
Show Gist options
  • Save ohAitch/565e88e3e19ab05e79b2 to your computer and use it in GitHub Desktop.
Save ohAitch/565e88e3e19ab05e79b2 to your computer and use it in GitHub Desktop.
A semi-imperative approach to repmin.
# tree: {fork: {leaf:"int", node: ["tree", "tree"]}}
repmin-mut = (tree) -> _repmin-mut tree, {leaf: Infinity}
_repmin-mut = (tree,min)-> switch Object.keys(tree)[0] # shh js totally has pattern-matching
when 'node' then {node: [(repmin-mut tree, min), (repmin-mut tree,min)]}
when 'leaf'
if min.leaf > tree.leaf
min.leaf = tree.leaf
min
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment