Last active
August 11, 2016 12:10
-
-
Save kaw2k/e61b0a8f05b1b1781b8c to your computer and use it in GitHub Desktop.
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
function treeNode(value, left, right) { | |
return { | |
value: value, | |
left: left, | |
right: right, | |
map: function(transformation) { | |
var nextValue = transformation(nextValue); | |
var nextLeft; | |
if (left) nextLeft = left.map(transformation); | |
var nextRight; | |
if (right) nextRight = right.map(transformation); | |
return treeNode(nextValue, nextLeft, nextRight); | |
} | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You've got a typo: line 7 should read:
As it currently stands, it's calling
transformation
on a value which doesn't yet exist. (It only runs without complaint because of the use ofvar
to bind the variable name.)