Skip to content

Instantly share code, notes, and snippets.

@sri-rang
Created December 25, 2011 15:51
Show Gist options
  • Save sri-rang/1519450 to your computer and use it in GitHub Desktop.
Save sri-rang/1519450 to your computer and use it in GitHub Desktop.
Functional Programming in JavaScript - 7
const CIRCLE = "circle";
const SQUARE = "square";
const RECTANGLE = "rectangle";
var getAreaFunction = function (shape) {
return function () {
switch (shape) {
case CIRCLE:
return Math.PI * arguments[0] * arguments[0];
break;
case SQUARE:
return arguments[0] * arguments[0];
break;
case RECTANGLE:
return arguments[0] * arguments[1];
break;
}
};
};
var getAreaOfCircle = getAreaFunction(CIRCLE);
var getAreaOfSquare = getAreaFunction(SQUARE);
var getAreaOfRectangle = getAreaFunction(RECTANGLE);
console.log(getAreaOfCircle(50));
console.log(getAreaOfSquare(50));
console.log(getAreaOfRectangle(50, 20));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment