I'm trying to learn functional programming in JavaScript, and I can't wrap my head around this higher-order function. I don't understand why calling g(1,2,3,4) results in [1]. I tried doing console.log("arg: ", arg) as below, and I don't understand why arg in the console.log is 1. Where does arg come from? How is arg passed to funcation one(arg)? Does it have anything to do with curry? Can someone explain it in a very simple and beginning level way?
function unary(fn) {
return function one(arg) {
console.log("arg: ", arg)
return fn(arg)
}
}
function f(...args) {
return args
}
var g = unary(f)
g(1,2,3,4) // [1]