Comparing version 0.1.0 to 0.5.0
@@ -17,1 +17,60 @@ ### 0.0.0 / 2012-02-25 | ||
- added distr | ||
### 0.2.0 / 2012-03-16 | ||
- added al | ||
- added ar | ||
- added list | ||
- added len | ||
- added first | ||
- added last | ||
- added butlast | ||
- added tail | ||
- added reverse | ||
- added repeat | ||
- added replica | ||
### 0.3.0 / 2012-03-16 | ||
- added insl | ||
- added insr | ||
- added bigger | ||
- added smaller | ||
- added biggest | ||
- added smallest | ||
- added cart | ||
- added sum | ||
- added sub | ||
- added mul | ||
- added div | ||
### 0.4.0 / 2012-03-16 | ||
- added E | ||
- added LN2 | ||
- added LN10 | ||
- added LOG2E | ||
- added LOG10E | ||
- added PI | ||
- added SQRT1_2 | ||
- added SQRT2 | ||
### 0.5.0 / 2012-03-16 | ||
- added abs | ||
- added acos | ||
- added asin | ||
- added atan | ||
- added atan2 | ||
- added ceil | ||
- added cos | ||
- added exp | ||
- added floor | ||
- added log | ||
- added pow | ||
- added random | ||
- added round | ||
- added sin | ||
- added sqrt | ||
- added tan | ||
640
lib/f.js
/*! | ||
* ƒ | ||
* JavaScript functional library | ||
* Copyright (c) 2011 Enrico Marino <enrico.marino@email.com> | ||
* Copyright (c) 2012 Enrico Marino <enrico.marino@email.com> | ||
* MIT License | ||
@@ -20,3 +20,3 @@ */ | ||
exports.version = '0.1.0'; | ||
ƒ.version = '0.5.0'; | ||
@@ -189,2 +189,636 @@ /** | ||
}(this)); | ||
/** | ||
* insl | ||
* insert left operator | ||
* given a binary associative `operator` | ||
* returns a function that given an array | ||
* returns the riduction of the array by the operator. | ||
* | ||
* @param {Function} operator binary operator | ||
* @return {Function} function that apply `operator` to the given `array` | ||
* @api public | ||
*/ | ||
ƒ.insl = function (operator) { | ||
return function (array) { | ||
return array.reduce(operator); | ||
}; | ||
}; | ||
/** | ||
* insl | ||
* insert left operator | ||
* given a binary associative `operator` | ||
* returns a function that given an array | ||
* returns the right riduction of the array by the operator. | ||
* | ||
* @param {Function} operator binary operator | ||
* @return {Function} function that apply `operator` to the given `array` | ||
* @api public | ||
*/ | ||
ƒ.insr = function (operator) { | ||
return function (array) { | ||
return array.reduceRight(operator); | ||
}; | ||
}; | ||
/** | ||
* al | ||
* append left | ||
* append `item` on the left of `array` | ||
* | ||
* @param {Array} pair | ||
* @param {Array} [pair[0]] array | ||
* @param {Any} [pair[1]] item | ||
* @return {Array} `array` concatenated with `item` | ||
* @api public | ||
*/ | ||
ƒ.al = function (pair) { | ||
var array = pair[0]; | ||
var item = pair[1]; | ||
return array.concat([item]); | ||
}; | ||
/** | ||
* ar | ||
* append right | ||
* append `item` on the right of `array` | ||
* | ||
* @param {Array} pair | ||
* @param {Any} [pair[0]] item | ||
* @param {Array} [pair[1]] array | ||
* @return {Array} `array` concatenated with `item` | ||
* @api public | ||
*/ | ||
ƒ.ar = function (pair) { | ||
var item = pair[0]; | ||
var array = pair[1]; | ||
return ([item]).concat(array); | ||
}; | ||
/** | ||
* last | ||
* returns the last element of the given `array` | ||
* | ||
* @param {Array} array array | ||
* @return {Any} the last element of `array` | ||
* @api public | ||
*/ | ||
ƒ.last = function (array) { | ||
return array[array.length - 1]; | ||
}; | ||
/** | ||
* list | ||
* returns an array containing `arg`. | ||
* | ||
* @param {Array} arg | ||
* @return {Array} array containing `arg` | ||
* @api public | ||
*/ | ||
ƒ.list = function (arg) { | ||
return [arg]; | ||
}; | ||
/** | ||
* len | ||
* returns the length of the given `array` | ||
* | ||
* @param {Array} array array | ||
* @return {Number} the length of the given `array` | ||
* @api public | ||
*/ | ||
ƒ.len = function (array) { | ||
return array.length; | ||
}; | ||
/** | ||
* first | ||
* returns the first element of the given `array`. | ||
* | ||
* @param {Array} array array | ||
* @return the first element of the given `array`. | ||
* @api public | ||
*/ | ||
ƒ.first = function (array) { | ||
return array[0]; | ||
}; | ||
/** | ||
* reverse | ||
* returns the given `array` in reverse order | ||
* | ||
* @param {Array} array array | ||
* @return {Array} the given `array` in reverse order | ||
* @api public | ||
*/ | ||
ƒ.reverse = function (array) { | ||
var result = []; | ||
var i; | ||
for (i = array.length - 1; i >= 0; i--) { | ||
result.push(array[i]); | ||
} | ||
return result; | ||
}; | ||
/** | ||
* tail | ||
* returns the non-empty `array` but its `first` element | ||
* | ||
* @param {Array} array array | ||
* @return {Array} the tail of the given `array` | ||
* @api public | ||
*/ | ||
ƒ.tail = function (array) { | ||
return array.slice(1); | ||
}; | ||
/** | ||
* butlast | ||
* returns the non-empty `array` but its `last` element | ||
* | ||
* @return {Array} the non-empty `array` but its `last` element | ||
* @api public | ||
*/ | ||
ƒ.butlast = function (array) { | ||
return array.slice(0,-1); | ||
}; | ||
/** | ||
* repeat | ||
* returns an array with `n` repetitions of `value` | ||
* | ||
* @param {Number} n number of repetitions | ||
* @return {Function} a function that given `value` | ||
* returns an array with `n` repetitions of `value` | ||
* @api public | ||
*/ | ||
ƒ.repeat = function (n) { | ||
return function (value) { | ||
var result = []; | ||
var i; | ||
for (i = 0; i < n; i++) { | ||
result.push(value); | ||
} | ||
return result; | ||
}; | ||
}; | ||
/** | ||
* replica | ||
* repeat list and catenate. | ||
* | ||
* @param {Number} n number of repetitions | ||
* @return {Function} a function that given `value` | ||
* returns an array with `n` repetitions of `value` concatenated | ||
* @api public | ||
*/ | ||
ƒ.replica = function (n) { | ||
return function (value) { | ||
var result = []; | ||
var i; | ||
for (i = 0; i < n; i++) { | ||
result.concat(value); | ||
} | ||
return result; | ||
}; | ||
}; | ||
/** | ||
* bigger | ||
* binary operator that returns the greater of the given pair | ||
* | ||
* @param {Array} pair | ||
* @return {Number} return the greater of the `pair` | ||
* @api public | ||
*/ | ||
ƒ.bigger = function (pair) { | ||
var a = pair[0]; | ||
var b = pair[1]; | ||
return a > b ? a : b; | ||
}; | ||
/** | ||
* smaller | ||
* binary operator that returns the smaller of the given pair | ||
* | ||
* @param {Array} pair | ||
* @return {Number} return the smaller of the `pair` | ||
* @api public | ||
*/ | ||
ƒ.smaller = function (pair) { | ||
var a = pair[0]; | ||
var b = pair[1]; | ||
return a < b ? a : b; | ||
}; | ||
/** | ||
* biggest | ||
* returns the greatest of the given `values` | ||
* | ||
* @param {Array} values values | ||
* @return {Number} return the greatest of the given `values` | ||
* @api public | ||
*/ | ||
ƒ.biggest = function (values) { | ||
return Math.max.apply(null, values); | ||
}; | ||
/** | ||
* smallest | ||
* returns the smallest of the given `values` | ||
* | ||
* @param {Array} values values | ||
* @return {Number} return the smallest of the given `values` | ||
* @api public | ||
*/ | ||
ƒ.smallest = function (values) { | ||
return Math.min.apply(null, values); | ||
}; | ||
/** | ||
* sum | ||
* returns the sum of the given `values` (numbers or arrays) | ||
* | ||
* @param {Array} values values | ||
* @return {Number} return the sum of the given `values` | ||
* @api public | ||
*/ | ||
ƒ.sum = function (values) { | ||
if (values[0] instanceof Array) { | ||
return values.reduce(function (prev, curr) { | ||
return prev.map(function (value, i) { | ||
return value + curr[i]; | ||
}); | ||
}; | ||
} | ||
return values.reduce(function (prev, curr) { | ||
return prev + curr; | ||
}); | ||
}; | ||
/** | ||
* sub | ||
* returns the difference of the given `values` (numbers or arrays) | ||
* | ||
* @param {Array} values values | ||
* @return {Number} return the difference of the given `values` | ||
* @api public | ||
*/ | ||
ƒ.sub = function (values) { | ||
if (values[0] instanceof Array) { | ||
return values.reduce(function (prev, curr) { | ||
return prev.map(function (value, i) { | ||
return value - curr[i]; | ||
}); | ||
}; | ||
} | ||
return values.reduce(function (prev, curr) { | ||
return prev - curr; | ||
}); | ||
}; | ||
/** | ||
* mul | ||
* multiplicate the given `values` | ||
* | ||
* @param {Array} values values | ||
* @return {Number} return the product of the given `values` | ||
* @api public | ||
*/ | ||
ƒ.mul = function (values) { | ||
if (values[0] instanceof Array) { | ||
return values.reduce(function (prev, curr) { | ||
return prev.map(function (value, i) { | ||
return value * curr[i]; | ||
}); | ||
}; | ||
} | ||
return values.reduce(function (prev, curr) { | ||
return prev * curr; | ||
}); | ||
}; | ||
/** | ||
* div | ||
* divide the given `values` | ||
* | ||
* @param {Array} values values | ||
* @return {Number} return the division of the given `values` | ||
* @api public | ||
*/ | ||
ƒ.div = function (values) { | ||
if (values[0] instanceof Array) { | ||
return values.reduce(function (prev, curr) { | ||
return prev.map(function (value, i) { | ||
return value / curr[i]; | ||
}); | ||
}; | ||
} | ||
return values.reduce(function (prev, curr) { | ||
return prev / curr; | ||
}); | ||
}; | ||
/** | ||
* cart | ||
* cartesian product | ||
* | ||
* @param {Array} args | ||
* @return {Array} the cartesian product of `args` | ||
* @api public | ||
*/ | ||
ƒ.cart = function (args) { | ||
return args.reduce(function (a, b) { | ||
var ret = []; | ||
a.forEach(function (a) { | ||
b.forEach(function (b) { | ||
ret.push(a.concat([b])); | ||
}); | ||
}); | ||
return ret; | ||
}, [[]]); | ||
}; | ||
/** | ||
* Math constant | ||
*/ | ||
/** | ||
* E | ||
* | ||
* @constant | ||
*/ | ||
ƒ.E = Math.E; | ||
/** | ||
* LN2 | ||
* | ||
* @constant | ||
*/ | ||
ƒ.LN2 = Math.LN2; | ||
/** | ||
* LN10 | ||
* | ||
* @constant | ||
*/ | ||
ƒ.LN10 = Math.LN10; | ||
/** | ||
* LOG2E | ||
* | ||
* @constant | ||
*/ | ||
ƒ.LOG2E = Math.LOG2E; | ||
/** | ||
* LOG10E | ||
* | ||
* @constant | ||
*/ | ||
ƒ.LOG10E = Math.LOG10E; | ||
/** | ||
* PI | ||
* | ||
* @constant | ||
*/ | ||
ƒ.PI = Math.PI; | ||
/** | ||
* SQRT1_2 | ||
* | ||
* @constant | ||
*/ | ||
ƒ.SQRT1_2 = Math.SQRT1_2; | ||
/** | ||
* SQRT2 | ||
* | ||
* @constant | ||
*/ | ||
ƒ.SQRT2 = Math.SQRT2; | ||
/** | ||
* abs | ||
* returns the absolute value of the given number | ||
* | ||
* @param {Number} number | ||
* @return {Number} the absolute value of the given number | ||
* @api public | ||
*/ | ||
ƒ.abs = Math.abs; | ||
/** | ||
* acos | ||
* returns the arc-cosine of the given number | ||
* | ||
* @param {Number} number | ||
* @return {Number} the arc-cosine of the given number | ||
* @api public | ||
*/ | ||
ƒ.acos = Math.acos; | ||
/** | ||
* asin | ||
* returns the arc-sine of the given number | ||
* | ||
* @param {Number} number | ||
* @return {Number} the arc-sine of the given number | ||
* @api public | ||
*/ | ||
ƒ.asin = Math.asin; | ||
/** | ||
* atan | ||
* returns the arc-tangent of the given number | ||
* | ||
* @param {Number} number | ||
* @return {Number} the arc-tangent of the given number | ||
* @api public | ||
*/ | ||
ƒ.atan = Math.atan; | ||
/** | ||
* atan2 | ||
* returns the squared arc-tangent of the given number | ||
* | ||
* @param {Number} number | ||
* @return {Number} the squred arc-tangent of the given number | ||
* @api public | ||
*/ | ||
ƒ.atan2 = Math.atan2; | ||
/** | ||
* ceil | ||
* returns the ceil of the given number | ||
* | ||
* @param {Number} number | ||
* @return {Number} the ceil of the given number | ||
* @api public | ||
*/ | ||
ƒ.ceil = Math.ceil; | ||
/** | ||
* cos | ||
* returns the cosine of the given number | ||
* | ||
* @param {Number} number | ||
* @return {Number} the cosine of the given number | ||
* @api public | ||
*/ | ||
ƒ.cos = Math.cos; | ||
/** | ||
* exp | ||
* returns the exponential of the given value (e^value) | ||
* | ||
* @param {Array} pair | ||
* @param {Number} [pair[0]] value | ||
* @param {Number} [pari[1]] n | ||
* @return {Number} the `n`-th power of the given number | ||
* @api public | ||
*/ | ||
ƒ.exp = Math.exp; | ||
/** | ||
* floor | ||
* returns the floor of the given number | ||
* | ||
* @param {Number} value | ||
* @return {Number} the floor of the given number | ||
* @api public | ||
*/ | ||
ƒ.floor = Math.floor; | ||
/** | ||
* log | ||
* returns the log of the given number | ||
* | ||
* @param {Number} value | ||
* @return {Number} the log of the given number | ||
* @api public | ||
*/ | ||
ƒ.log = Math.log; | ||
/** | ||
* floor | ||
* returns the floor of the given number | ||
* | ||
* @param {Number} value | ||
* @return {Number} the floor of the given number | ||
* @api public | ||
*/ | ||
ƒ.floor = Math.floor; | ||
/** | ||
* power | ||
* returns the n-th power of the given value (value^n) | ||
* | ||
* @param {Array} pair | ||
* @param {Number} [pair[0]] value | ||
* @param {Number} [pari[1]] n | ||
* @return {Number} the `n`-th power of the given number | ||
* @api public | ||
*/ | ||
ƒ.pow = function (pair) { | ||
return Math.exp.apply(pair); | ||
}; | ||
/** | ||
* random | ||
* returns a random number in [0, 1) interval | ||
* | ||
* @return {Number} a random number in [0, 1) interval | ||
* @api public | ||
*/ | ||
ƒ.random = Math.random; | ||
/** | ||
* round | ||
* returns the given number rounded | ||
* | ||
* @return {Number} the given number rounded | ||
* @api public | ||
*/ | ||
ƒ.round = Math.round; | ||
/** | ||
* sin | ||
* returns the sine of the given number | ||
* | ||
* @return {Number} the sin of the given number | ||
* @api public | ||
*/ | ||
ƒ.sin = Math.sin; | ||
/** | ||
* sqrt | ||
* returns the squared root of the given number | ||
* | ||
* @return {Number} the squared root of the given number | ||
* @api public | ||
*/ | ||
ƒ.sqrt = Math.sqrt; | ||
/** | ||
* tan | ||
* returns the tan of the given number | ||
* | ||
* @return {Number} the tan of the given number | ||
* @api public | ||
*/ | ||
ƒ.tan = Math.tan; | ||
}(this)); |
@@ -9,3 +9,3 @@ { | ||
"description": "JavaScript functional library", | ||
"version": "0.1.0", | ||
"version": "0.5.0", | ||
"homepage": "https://github.com/onirame/f", | ||
@@ -12,0 +12,0 @@ "repository": { |
@@ -21,2 +21,48 @@ # ƒ | ||
- ƒ.distr | ||
- ƒ.al | ||
- ƒ.ar | ||
- ƒ.list | ||
- ƒ.len | ||
- ƒ.first | ||
- ƒ.last | ||
- ƒ.butlast | ||
- ƒ.tail | ||
- ƒ.reverse | ||
- ƒ.repeat | ||
- ƒ.replica | ||
- ƒ.insl | ||
- ƒ.insr | ||
- ƒ.bigger | ||
- ƒ.smaller | ||
- ƒ.biggest | ||
- ƒ.smallest | ||
- ƒ.cart | ||
- ƒ.sum | ||
- ƒ.sub | ||
- ƒ.mul | ||
- ƒ.div | ||
- ƒ.E | ||
- ƒ.LN2 | ||
- ƒ.LN10 | ||
- ƒ.LOG2E | ||
- ƒ.LOG10E | ||
- ƒ.PI | ||
- ƒ.SQRT1_2 | ||
- ƒ.SQRT2 | ||
- ƒ.abs | ||
- ƒ.acos | ||
- ƒ.asin | ||
- ƒ.atan | ||
- ƒ.atan2 | ||
- ƒ.ceil | ||
- ƒ.cos | ||
- ƒ.exp | ||
- ƒ.floor | ||
- ƒ.log | ||
- ƒ.pow | ||
- ƒ.random | ||
- ƒ.round | ||
- ƒ.sin | ||
- ƒ.sqrt | ||
- ƒ.tan | ||
@@ -23,0 +69,0 @@ ## License |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
19190
696
91
1