Last active
December 16, 2015 08:09
-
-
Save nadinengland/5404126 to your computer and use it in GitHub Desktop.
Parsing if expressions in CoffeeScript and JavaScript
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
var funcs = [ | |
function () { if (true) if (true) return 0; else return 1; }, // 0 | |
function () { if (true) { if (true) return 0; else return 1; } }, // 0 | |
function () { if (true) { if (true) return 0; } else return 1; }, // 0 | |
function () { if (false) if (true) return 0; else return 1; }, // undefined | |
function () { if (false) { if (true) return 0; else return 1; } }, // undefined | |
function () { if (false) { if (true) return 0; } else return 1; }, // 1 | |
function () { if (true) if (false) return 0; else return 1; }, // 1 | |
function () { if (true) { if (false) return 0; else return 1; } }, // 1 | |
function () { if (true) { if (false) return 0; } else return 1; }, // undefined | |
function () { if (false) if (false) return 0; else return 1; }, // undefined | |
function () { if (false) { if (false) return 0; else return 1; } }, // undefined | |
function () { if (false) { if (false) return 0; } else return 1; } // 1 | |
]; | |
funcs.forEach(function (fn) { | |
console.log(fn()); | |
}); |
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
funcs = [ | |
( -> if true then if true then 0 else 1 ), # 0 | |
( -> if true then ( if true then 0 else 1 ) ), # 0 | |
( -> if true then ( if true then 0 ) else 1 ), # 0 | |
( -> if false then if true then 0 else 1 ), # 1 | |
( -> if false then ( if true then 0 else 1 ) ), # undefined | |
( -> if false then ( if true then 0 ) else 1 ), # 1 | |
( -> if true then if false then 0 else 1 ), # undefined | |
( -> if true then ( if false then 0 else 1 ) ), # 1 | |
( -> if true then ( if false then 0 ) else 1 ), # undefined | |
( -> if false then if false then 0 else 1 ), # 1 | |
( -> if false then ( if false then 0 else 1 ) ), # undefined | |
( -> if false then ( if false then 0 ) else 1 ), # 1 | |
] | |
funcs.forEach (fn) -> | |
console.log fn() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment