Created
May 19, 2025 15:32
-
-
Save ALNDL63/a233f3c03fcd397079eb57c7513d6570 to your computer and use it in GitHub Desktop.
Este es mi desafío para el buscador de películas. He seguido la consigna y he implementado las funcionalidades requeridas. Si hay algo que podría mejorar, agradecería mucho los comentarios. ¡Gracias!
This file contains hidden or 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 path = require("path"); | |
// Importar funciones de pelis.js | |
const { getMovies, sortMovies, searchMovies, filterByTag } = require("./pelis"); | |
// Leer argumentos de la terminal | |
const args = process.argv.slice(2); | |
// Función principal | |
const main = () => { | |
const movies = getMovies(); // Obtener todas las películas | |
if (args.length === 0) { | |
console.table(movies); // Mostrar todas las películas | |
} else if (args[0] === "--sort") { | |
console.table(sortMovies(movies, args[1])); // Ordenar películas | |
} else if (args[0] === "--search") { | |
console.table(searchMovies(movies, args[1])); // Buscar películas | |
} else if (args[0] === "--tag") { | |
console.table(filterByTag(movies, args[1])); // Filtrar por tag | |
} else { | |
console.log("Argumento no reconocido"); | |
} | |
}; | |
main(); |
This file contains hidden or 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 path = require("path"); | |
// Leer el archivo JSON | |
const getMovies = () => { | |
const data = fs.readFileSync(path.join(__dirname, "pelis.json")); | |
return JSON.parse(data); | |
}; | |
// Ordenar películas | |
const sortMovies = (movies, property) => { | |
return movies.sort((a, b) => a[property].localeCompare(b[property])); | |
}; | |
// Buscar películas | |
const searchMovies = (movies, criteria) => { | |
return movies.filter((movie) => | |
movie.title.toLowerCase().includes(criteria.toLowerCase()) | |
); | |
}; | |
// Filtrar por tag | |
const filterByTag = (movies, tag) => { | |
return movies.filter((movie) => movie.tags.includes(tag)); | |
}; | |
module.exports = { getMovies, sortMovies, searchMovies, filterByTag }; |
This file contains hidden or 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": "Tiburon", | |
"rating": 4, | |
"tags": ["suspenso", "favorita", "exito"], | |
"año": "1975" | |
}, | |
{ | |
"title": "El Exorcista", | |
"rating": 5, | |
"tags": ["terror", "culto", "exito"], | |
"año": "1978" | |
}, | |
{ | |
"title": "Cinema Paradiso", | |
"rating": 5, | |
"tags": ["drama", "favorita", "europea"], | |
"año": "1988" | |
}, | |
{ | |
"title": "La Aventura del Poseidon", | |
"rating": 5, | |
"tags": ["Aventuras", "catastrofe", "drama"], | |
"año": "1972" | |
}, | |
{ | |
"title": "Duro de matar", | |
"rating": 4, | |
"tags": ["aventuras", "policial", "accion"], | |
"año": "1988" | |
}, | |
{ | |
"title": "Terminator", | |
"rating": 5, | |
"tags": ["Aventuras", "ciencia ficcion", "accion"], | |
"año": "1984" | |
} | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment