Created
April 23, 2025 20:11
-
-
Save FranGiorgianni00/ae974823ad0f4c79492c3acce53843aa to your computer and use it in GitHub Desktop.
Desafío buscador de películas Nivel1
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 { leerPeliculas, ordenarPeliculas, buscarPeliculas, filtrarPorTag } = require('./pelis'); | |
const args = process.argv.slice(2); | |
const peliculas = leerPeliculas(); | |
console.log(peliculas); | |
if (args.length === 0) { | |
console.table(peliculas); | |
} else if (args[0] === '--sort') { | |
const propiedad = args[1]; | |
const peliculasOrdenadas = ordenarPeliculas(peliculas, propiedad); | |
console.table(peliculasOrdenadas); | |
} else if (args[0] === '--search') { | |
const criterio = args[1]; | |
const resultados = buscarPeliculas(peliculas, criterio); | |
console.table(resultados); | |
} else if (args[0] === '--tag') { | |
const tag = args[1]; // Tag para filtrar | |
const resultados = filtrarPorTag(peliculas, tag); | |
console.table(resultados); | |
} |
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 leerPeliculas = () => { | |
try { | |
const data = fs.readFileSync(__dirname + '/pelis.json', 'utf8'); | |
return JSON.parse(data); | |
} catch (error) { | |
console.error('Error al leer el archivo:', error); | |
} | |
}; | |
const ordenarPeliculas = (peliculas, propiedad) => { | |
return peliculas.sort((a, b) => { | |
if (a[propiedad] < b[propiedad]) return -1; | |
if (a[propiedad] > b[propiedad]) return 1; | |
return 0; | |
}); | |
}; | |
const buscarPeliculas = (peliculas, criterio) => { | |
return peliculas.filter(pelicula => | |
pelicula.title.toLowerCase().includes(criterio.toLowerCase()) | |
); | |
}; | |
const filtrarPorTag = (peliculas, tag) => { | |
return peliculas.filter(pelicula => | |
pelicula.tags.includes(tag) | |
); | |
}; | |
module.exports = { leerPeliculas, ordenarPeliculas, buscarPeliculas, filtrarPorTag }; |
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": "Inception", | |
"rating": 8.8, | |
"tags": ["acción", "ciencia ficción", "thriller"] | |
}, | |
{ | |
"title": "The Godfather", | |
"rating": 9.2, | |
"tags": ["drama", "crimen"] | |
}, | |
{ | |
"title": "The Dark Knight", | |
"rating": 9.0, | |
"tags": ["acción", "superhéroes", "thriller"] | |
}, | |
{ | |
"title": "Pulp Fiction", | |
"rating": 8.9, | |
"tags": ["drama", "crimen"] | |
}, | |
{ | |
"title": "The Shawshank Redemption", | |
"rating": 9.3, | |
"tags": ["drama", "suspenso"] | |
}, | |
{ | |
"title": "Forrest Gump", | |
"rating": 8.8, | |
"tags": ["drama", "romance"] | |
}, | |
{ | |
"title": "The Matrix", | |
"rating": 8.7, | |
"tags": ["acción", "ciencia ficción"] | |
}, | |
{ | |
"title": "Fight Club", | |
"rating": 8.8, | |
"tags": ["drama", "acción"] | |
}, | |
{ | |
"title": "The Lord of the Rings: The Return of the King", | |
"rating": 8.9, | |
"tags": ["fantasía", "aventura"] | |
}, | |
{ | |
"title": "Interstellar", | |
"rating": 8.6, | |
"tags": ["ciencia ficción", "drama"] | |
} | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment