Created
July 11, 2015 19:39
-
-
Save ohAitch/565e88e3e19ab05e79b2 to your computer and use it in GitHub Desktop.
A semi-imperative approach to repmin.
This file contains 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
# 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