Last active
June 29, 2018 17:30
-
-
Save bradcypert/1487efc0277aca13236c15bd78cf6ce7 to your computer and use it in GitHub Desktop.
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
function when(constraints) { | |
for(obj of constraints) { | |
var ths = obj['this']; | |
var d = obj['do']; | |
if (ths && typeof ths === "function" && d && typeof d === "function") { | |
var response = ths(); | |
if (response === true) return d() | |
} | |
} | |
} | |
when([ | |
{this: function() {return true}, do: function() {console.log("woo")}}, | |
{this: function() {return false}, do: function() {console.log("oh no")}} | |
]) | |
let resp = when([ | |
{this: () => true, do: () => 1234} | |
]) | |
console.log(resp); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment