-
-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy path_if.js
More file actions
14 lines (9 loc) · 644 Bytes
/
_if.js
File metadata and controls
14 lines (9 loc) · 644 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
/*
Who likes keywords? Nobody likes keywords, so why use them?
You know what keyword I use too much? if! We should make a function called _if, with its arguments as a logical test and two functions/lambdas where the first function is executed if the boolean is true, and the second if it's false, like an if/else statement, so that we don't have to mess around with those nasty keywords! Even so, It should support truthy/falsy types just like the keyword.
Example:
_if(true, function(){console.log("True")}, function(){console.log("false")})
// Logs 'True' to the console.
*/
//Answer//
let _if=(bool, func1, func2)=>bool?func1():func2()