johnhenry/polyfill-function

JavaScript
Switch branches/tags
Nothing to show
Fetching latest commitâ€¦
Cannot retrieve the latest commit at this time.

#Polyfill - Function

##Node

Installation

``````    \$ npm install polyfill-function
``````

Usage Example

```    require('polyfill-function');

var recursive = function(func,seeds___){
var seeds = Array.prototype.slice.call(arguments,1);
return function(step){
if(step < seeds.length) return seeds[step];
var ns = seeds.slice(0);
while(--step +1) ns.pushOff(func.apply(this,ns));
return ns[ns.length - 1];
}
}
var fib = recursive(function(a,b){return a+b},0,1);//Alternative definition of the Fibonacci Sequence
```

##Web

Installation

`   <script src="./lib/polyfill-function.js" ></script>`

Usage Example

```    <!--This particular example requires the pushOff method from the polyfill-array library located here: https://github.com/johnhenry/polyfill-array -->
<script src="./lib/polyfill-array.js" ></script>
<script>
var recursive2 = function(func,seeds___){
var seeds = Array.prototype.slice.call(arguments,1)
return function(step){
if(step < seeds.length) return seeds[step]
return (function(ns){
return ns.pushOff(func.apply(this,ns));
}).chain(step)(seeds.slice(0))[seeds.length-1]
}
}
var fib2 = recursive2(function(a,b){return a+b},0,1);//Alternative alternative definition of the Fibonacci Sequence
var fib2mem = fib2.memoize();//Memoized version of the Fibonacci Sequence
</script>```