functional-light
Advanced tools
Comparing version 0.5.1 to 0.6.0
@@ -134,2 +134,29 @@ /** | ||
module.exports = { cons, first, rest, isEmpty, isList, length, append, filter, map, deepCopy }; | ||
/** | ||
* Aplica una función f a cada elemento de la lista. La función f | ||
* recibe el elemento de la lista y el índice en el cual se encuentra. | ||
* El tercer parámetro es un desplazamiento del índice. Por defecto en 0 | ||
* @param {Array} l | ||
* @param {function} f | ||
* @param {number} offset | ||
* @example forEach([1, 2, 3], (a, i) => console.log(i + " : " + a)); | ||
*/ | ||
function forEach(l, f, index = 0) { | ||
if (!isEmpty(l)) { | ||
f(first(l), index); | ||
forEach(rest(l), f, index + 1); | ||
} | ||
} | ||
/** | ||
* Concatena 2 listas. | ||
* @param {Array} list1 | ||
* @param {Array} list2 | ||
* @returns {Array} | ||
* @example concat([1, 2], [3, 4]); // [1, 2, 3, 4] | ||
*/ | ||
function concat(list1, list2) { | ||
if (isEmpty(list1)) return list2; | ||
return cons(first(list1), concat(rest(list1), list2)); | ||
} | ||
module.exports = { cons, first, rest, isEmpty, isList, length, append, filter, map, deepCopy, forEach, concat }; |
{ | ||
"name": "functional-light", | ||
"version": "0.5.1", | ||
"version": "0.6.0", | ||
"description": "Librería para el curso de programación funcional con JavaScript", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10484
148