Skip to content

Instantly share code, notes, and snippets.

@andreasvirkus
Created June 28, 2016 14:34
Show Gist options
  • Save andreasvirkus/508d02f29d16cbb42fda333bb61b4821 to your computer and use it in GitHub Desktop.
Save andreasvirkus/508d02f29d16cbb42fda333bb61b4821 to your computer and use it in GitHub Desktop.
// Condensed logical operators
var operators = new Function("return {"+ "==,===,!=,!==,<,>,<=,>=" .replace(/([^,]+)/g, "'$1': function (l, r) { return l $1 r; }\n")+ ",'typeof': function (l, r) { return typeof l == r; } }")();
// And beating 'round the bush
var operators = {
'==': function (l, r) { return l == r; },
'===': function (l, r) { return l === r; },
'!=': function (l, r) { return l != r; },
'!==': function (l, r) { return l !== r; },
'<': function (l, r) { return l < r; },
'>': function (l, r) { return l > r; },
'<=': function (l, r) { return l <= r; },
'>=': function (l, r) { return l >= r; },
'typeof': function (l, r) { return typeof l == r; }
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment