Skip to content

Instantly share code, notes, and snippets.

@nadinengland
Last active December 16, 2015 08:09
Show Gist options
  • Save nadinengland/5404126 to your computer and use it in GitHub Desktop.
Save nadinengland/5404126 to your computer and use it in GitHub Desktop.
Parsing if expressions in CoffeeScript and JavaScript
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());
});
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