Last active
September 17, 2018 15:47
-
-
Save Anna-Myzukina/9a7cb3c29bbadfee2518e070c6307bf3 to your computer and use it in GitHub Desktop.
Cyrrying in js
This file contains hidden or 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 identity(args) { | |
return args; | |
} | |
module.exports = identity; |
This file contains hidden or 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 binary(first, second){ | |
return first + second; | |
} | |
module.exports = binary; | |
This file contains hidden or 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 unary(inputFirst) { | |
return function unaryNew(inputSecond) { | |
return inputFirst + inputSecond; | |
} | |
} | |
module.exports = unary; |
This file contains hidden or 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
var sum = 0; | |
function func(argFirst) { | |
if (argFirst === undefined) { | |
var result = sum; | |
sum = null; | |
return result; | |
} else { | |
sum += argFirst; | |
return func; | |
} | |
}; | |
module.exports = func; | |
This file contains hidden or 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
var callAndApply = { | |
caller: function (object, method, nameArg, ageArg, tShirtSizeArg) { | |
//your code | |
method.call(object, nameArg, ageArg, tShirtSizeArg) | |
}, | |
applier: function (object, method, argumentsArr) { | |
//your code | |
method.apply(object, argumentsArr); | |
} | |
}; | |
module.exports = callAndApply; | |
This file contains hidden or 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 abc(fn) { | |
var arr = fn.length; | |
return function curried(...args) { | |
if (args.length < arr) { | |
return (...nextArgs) => | |
curried(...args, ...nextArgs); | |
} | |
return fn(...args) | |
}; | |
} | |
module.exports = abc; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment