function array(a,n){
return Array.prototype.slice.call(a,n || 0);
}
//the arguments to this function are passed on the left
function particalLeft(f){
var args = arguments;
return function(){
var a = array(args,1);
a = a.concat(array(arguments));
return f.apply(this,a);
}
}
//the arguments to this function are passed on the right
function particalRight(f){
var args = arguments;
return function(){
var a = array(arguments);
a = a.concat(array(args, 1));
return f.apply(this, a);
}
}
//The arguments to this function serve as a templete, Undefined values in the argument list are filled in with values from the inner set
function partical(f){
var args = arguments;
return function(){
var a = array(arguments);
var length = a.length;
var j = 0;
for(var i = 0; i< length; i++){
if(a[i] === undefined){
a[i] = arguments[j++];
}
}
a = a.concat(array(arguments,j));
return f.apply(this,a);
}
}
function f(x,y,z){
return x*(y-z);
}
var result1 = particalLeft(f,2,3)(4);
var result2 = particalRight(f,2)(3,4);
var result3 = partical(f,undefined)(2,3,4);
console.log(result1);
console.log(result2);
console.log(result3);