-
-
Save RossiniMaximo/bef8844fae3d1f20df708acfa756d97f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const peliculas = require("./pelis.js"); | |
function parsed (argv) { | |
var obj = {}; | |
argv.forEach((item,ind) => { | |
if (item.startsWith("--")){ | |
var itemLimpio = item.slice(2); | |
obj[itemLimpio] = argv [ind + 1]; | |
} | |
}) | |
return obj | |
} | |
function main () { | |
const argumentos = process.argv.slice(2); | |
const ArgsParseados = parsed(argumentos); | |
const ejecucion = peliculas.searchByCriteria(ArgsParseados); | |
console.log(ejecucion); | |
}; | |
main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require("fs"); | |
const archivoPelis = fs.readFileSync( __dirname +"/pelis.json"); | |
const archivoToString = archivoPelis.toString(); | |
const parseArchivo = JSON.parse(archivoToString); | |
const getAll = (collection) => { | |
return parseArchivo; | |
} | |
const sortBy = function (propiedad, arrayDePelis) { | |
const datos = arrayDePelis; | |
var datosOrdenados = datos.sort((a, b) => { | |
if (a[propiedad] > b[propiedad]) { | |
return 1; | |
} | |
if (a[propiedad] < b[propiedad]) { | |
return -1; | |
} | |
return 0; | |
}); | |
return datosOrdenados; | |
}; | |
const getSimilarities = (palabra,arrayDePelis) => { | |
const datos = arrayDePelis | |
const encuentraSimilitudes = datos.filter((objeto) => { | |
if (objeto.title == palabra || objeto.title.includes(palabra)){ | |
return objeto; | |
}; | |
}); | |
return encuentraSimilitudes; | |
}; | |
const getByTag = (palabra,arrayDePelis) => { | |
const datos = arrayDePelis | |
const encuentraTags = datos.filter((objeto) => { | |
if ( objeto.tags.includes(palabra)){ | |
return objeto | |
} | |
}) | |
return encuentraTags; | |
} | |
const noFormat = (collection) => { | |
return JSON.stringify(collection); | |
}; | |
exports.searchByCriteria = function (criterio) { | |
var peliculas = getAll(); | |
if (criterio.length < 1){ | |
return peliculas | |
} | |
if (criterio.sort ){ | |
peliculas = (sortBy(criterio.sort,peliculas)); | |
}; | |
if ( criterio.search){ | |
peliculas = (getSimilarities(criterio.search,peliculas)); | |
}; | |
if (criterio.tags){ | |
peliculas = (getByTag(criterio.tags,peliculas)); | |
}; | |
if (criterio.hasOwnProperty("no-format")){ | |
peliculas = (noFormat(peliculas)) | |
}; | |
return peliculas | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[{ | |
"title" : "Interstellar", | |
"rating" : 10, | |
"tags" : "[ciencia ficción]" | |
}, | |
{ | |
"title" : "Batman begins", | |
"rating" : 8.5, | |
"tags" : "[acción,Aventura drama,Suspenso]" | |
}, | |
{ | |
"title" : "The joker", | |
"rating" : 9.5, | |
"tags" : "[Drama,Suspenso,Crimen,Thriller psicológico]" | |
}, | |
{ | |
"title" : "Relatos salvajes", | |
"rating" : 7, | |
"tags" : "[Comedia,Thriller cómico,drama,suspenso]" | |
}, | |
{ | |
"title" : "Avatar", | |
"rating" : 10, | |
"tags" : "[ciencia ficción,aventura,acción,fantástico,animación]" | |
}, | |
{ | |
"title" : "Avatar la leyenda de Anng", | |
"rating" : 6, | |
"tags" : "[fantasia,aventura]" | |
} | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Gracias facu por la revision, me gustaron las recomendaciones!