functional-light
Advanced tools
Comparing version 0.3.1 to 0.4.0
@@ -103,3 +103,3 @@ /** | ||
} else if (f(first(l))) { | ||
return cons(first(l), filter(rest(l), f)); | ||
return cons(deepCopy(first(l)), filter(rest(l), f)); | ||
} else { | ||
@@ -121,6 +121,16 @@ return filter(rest(l), f); | ||
} else { | ||
return cons(f(first(a)), map(rest(a), f)); | ||
return cons(deepCopy(f(first(a))), map(rest(a), f)); | ||
} | ||
}; | ||
module.exports = { cons, first, rest, isEmpty, isList, length, append, filter, map }; | ||
/** | ||
* Realiza una copia profunda(recursiva) del objeto que se pasa como parámetro | ||
* @param {object} value | ||
* @returns {object} | ||
* @example deepCopy({a: 10, b: {a: 45}}); // => {a: 10, b: {a: 45}} | ||
*/ | ||
let deepCopy = function (value) { | ||
return JSON.parse(JSON.stringify(value)); | ||
}; | ||
module.exports = { cons, first, rest, isEmpty, isList, length, append, filter, map, deepCopy }; |
{ | ||
"name": "functional-light", | ||
"version": "0.3.1", | ||
"version": "0.4.0", | ||
"description": "Librería para el curso de programación funcional con JavaScript", | ||
@@ -37,3 +37,4 @@ "keywords": [ | ||
"prepublish": "npm run compile", | ||
"jsdoc": "jsdoc2md src/index.js > docs/functional-light.md" | ||
"jsdoc": "jsdoc2md src/index.js > docs/functional-light.md", | ||
"publish": "npm publish" | ||
}, | ||
@@ -44,6 +45,6 @@ "devDependencies": { | ||
"chai": "4.2.0", | ||
"eslint": "^5.15.3", | ||
"eslint-config-cheminfo": "^1.20.1", | ||
"eslint-plugin-import": "^2.16.0", | ||
"eslint-plugin-jest": "^22.4.1", | ||
"eslint": "^6.6.0", | ||
"eslint-config-cheminfo": "^2.0.4", | ||
"eslint-plugin-import": "^2.18.2", | ||
"eslint-plugin-jest": "^23.0.2", | ||
"jest": "^24.5.0", | ||
@@ -50,0 +51,0 @@ "jsdoc-to-markdown": "^5.0.0", |
@@ -28,3 +28,5 @@ # Programación funcional con JavaScript | ||
console.log(cons(1, [2, 3])); // [] | ||
console.log(length(cons(1, [2, 3]))); // 3 | ||
const foo = cons(484, []); | ||
@@ -129,1 +131,26 @@ console.log(cons('XX', foo)) | ||
``` | ||
## Crear una suite de pruebas usando JEST | ||
Para crear las pruebas de las funciones vamos a utilizar el framework para pruebas JEST. | ||
La pruebas se deben poner una carpeta con nombre __tests__. A continuación se muesta un ejemplo de suite de pruebas. deepEqual sirve para hacer pruebas sobre arreglos | ||
``` js | ||
const { assert } = require('chai'); | ||
const { cons, first, rest, isEmpty, isList, append, length, filter, map } = require('../'); | ||
describe('functional-light', () => { | ||
it('test cons', () => { | ||
assert.typeOf(cons('1', []), 'array'); // ['1'] | ||
assert.deepEqual(cons('1', []), ['1']); // ['1'] | ||
assert.deepEqual(cons('2', cons('1', [])), ['2', '1']); // ['2', '1'] | ||
assert.deepEqual(cons(1, [2, 3]), [1, 2, 3]); | ||
const foo = cons(484, []); | ||
cons('XX', foo) | ||
assert.deepEqual(foo, cons(484, [])); | ||
}); | ||
} | ||
``` |
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
9682
122
155