$Interview_Questions
by mtambulut
JavaScript
'use strict';
/** First Way
function sum(x, y) {
if (y !== undefined) {
return x + y;
} else {
return function(y) { return x + y; };
}
}
function sum(x) {
alert(arguments.length);
if (arguments.length == 2) {
alert("a");
return arguments[0] + arguments[1];
} else {
console.log(x);
alert("b");
return function(y) {return x+s; };
}
}
function sum(x) {
return function(y) {
if (typeof y !== 'undefined') {
x = x + y;
return arguments.caller;
} else {
return x;
}
};
}
*/
function sum(x, gs) {
//alert(arguments.length);
if (typeof gs === "undefined") { // partial
return function (gs) {
return x + gs;
};
}
// full application
return x + gs;
}
//Burada aslında "sum()()" ikinci parantez aslında bir fonksiyonu ifade eder
//Bu fonksıyonu cagırarak degerı yukleyebılırız
//console.log(sum(2,3));
console.log(sum(1)(3));