Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function add(a, b) {
- return a + b;
- }
- function sub(a, b) {
- return a - b;
- }
- function mul(a, b) {
- return a * b;
- }
- add(4, 5); /*? */
- sub(12, 4); /*? */
- mul(3, 4); /*? */
- function identityf(arg) {
- return function() {
- return arg;
- }
- }
- var three = identityf(3);
- three(); /*? */
- function addf(a) {
- return function(b) {
- return a + b;
- }
- }
- addf(3)(4); /*? */
- function liftf(fn) {
- return function(a) {
- return function(b) {
- return fn(a, b); /*? */
- }
- }
- }
- var addf = liftf(add);
- addf(3)(4); /*? */
- liftf(mul)(3)(4); /*? */
- function curry(fn, arg) {
- return function(x) {
- return fn(arg, x); /*? */
- }
- }
- var add3 = curry(add, 3); /*? */
- add3(4); /*? */
- curry(mul, 5)(6);/*? */
- // var inc = addf(1); /*? */
- // var inc = liftf(add)(1);
- var inc = curry(add, 1);
- inc(5); /*? */
- inc = liftf(add)(1); /*? */
- inc(inc(5)); /*? */
- function twice(fn) {
- return function(x) {
- return fn(x, x); /*? */
- }
- }
- add(11, 11); /*? */
- var doubl = twice(add);
- doubl(11); /*? */
- function reverse(fn) {
- return function(...args) {
- return fn(...args.reverse());
- }
- }
- var bus = reverse(sub); /*? */
- bus(3, 2); /*? */
- function composeu(fn, fn1) {
- return function(x) {
- return fn1(fn(x));
- }
- }
- composeu(doubl, mul)(5); /*? */
Add Comment
Please, Sign In to add comment