Skip to content

Instantly share code, notes, and snippets.

@seba-campo
Created January 17, 2022 17:12
Show Gist options
  • Save seba-campo/5f10e22b190f3f321810423e29506218 to your computer and use it in GitHub Desktop.
Save seba-campo/5f10e22b190f3f321810423e29506218 to your computer and use it in GitHub Desktop.
Capitulo 22 - Modulos
function main(){
const products = require('./Products.js');
console.log(products.getOne(44));
console.table(products.getAll());
console.table(products.getAllWith(56));
}
main();
const productos = [{ id: 123, nombre:"producto 1", stock:3 },
{ id: 1323, nombre:"producto 2", stock:1 },
{ id: 1253, nombre:"producto 3", stock:2 },
{ id: 32, nombre:"producto 4", stock:63 },
{ id: 1623, nombre:"producto 5", stock:35 },
{ id: 3, nombre:"producto 6", stock:53 },
{ id: 25, nombre:"producto 7", stock:66 },
{ id: 37, nombre:"producto 8", stock:53 },
{ id: 34, nombre:"producto 9", stock:343 },
{ id: 177, nombre:"producto 10", stock:745 },
{ id: 34, nombre:"producto 11", stock:53 },
{ id: 13, nombre:"producto 12", stock:555 },
{ id: 44, nombre:"Optimizador", stock:7 }
];
exports.getOne = function (id){
const busqueda = productos.find((r) => {
return r.id == [id];
})
return busqueda
};
exports.getAll = function (){
return productos;
};
exports.getAllWith = function (minStock){
const filtrado = productos.filter((el) => {
return el.stock > [minStock];
});
return filtrado
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment