JSFiddle - React, Tailwind, and code Playground

by samur3

JavaScript

function identity(a) {
    return a;
}

function add(a, b) {
    return a + b;
}

function mul(a, b) {
    return a * b;
}

//function idf()
//{
//  return identity(a);
//}

function identity(x) {
    return function () {
        return x;
    };
}

function addf(x) {
    return function (y) {
        return x + y;
    };
}

function applyf(mul) {
    return function (x) {
        return function (y) {
            return mul(x, y);
        };
    };
}

function curry(func, first) {
    return function (second) {
        return func(first, second);
    };
}

function inc(x) {
    //return add(x,1);
    return addf(x)(1);
    //return curry(add,x)(1);
}

function twice(func) {
    return function (a) {
        return func(a, a);
    };
}

//function composeu(func1,func2) {
//   return function(a) {
//        var b = func1(a,a);
//        return func2(b,b);
//    };
//}

function composeu(f, g) {
    return function (a) {
        return g(f(a));
    };
}

function composeb(f, g) {
    return function (a, b, c) {
        return g(f(a, b), c);
    };
};

function once(func) {
    return function () {
        var f = func;
        func = null;
        return f.apply(this, arguments);
    };
}

function counterf(value) {
    return {
        inc: function() {
            value += 1;
            return value;
        },
        dec: function() {
            value -= 1;
            return value;
        }
    };
}

function revocable(func) {     
    return {
        invoke: function() {                        
            return func.apply(null,arguments);
        },
        revoke: function() {
             func = null;
        }
    };
}

var x = 3;
var y = 4;
var temp = revocable(alert);
//console.log(temp.invoke(x));
console.log(temp.revoke());
//add_once = once(add);
//console.log(counterf(10).inc());
//console.log(composeb(add,mul)(2,3,5));
//console.log(composeu(add,mul)(3));
//console.log(twice(mul)(4));
//console.log(inc(inc(5)));
//console.log(curry(mul,...