Advertisement
ADL_Rodrigo_Silva

Untitled

May 25th, 2022
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. const deportistas = [
  3.     {
  4.         id:1,
  5.         nombre:"Rodrigo"
  6.     },
  7.     {
  8.         id:2,
  9.         nombre:"Consuelo"
  10.     },
  11.     {
  12.         id:3,
  13.         nombre:"Sergio"
  14.     },
  15.     {
  16.         id:4,
  17.         nombre:"Milford"
  18.     }
  19. ];
  20.  
  21. const deportes = [
  22.     {
  23.         id:1,
  24.         deporte:"Pesas"
  25.     },
  26.     {
  27.         id:2,
  28.         deporte:"Volley"
  29.     },
  30.     {
  31.         id:3,
  32.         deporte:"Zumba"
  33.     }
  34. ];
  35.  
  36. // DEFINICIÓN DE LA FUNCIÓN GETDEPORTISTA
  37. const getDeportista =  (id, callback) => {
  38.     const  deportista = deportistas.find( d => d.id === id)?.nombre;
  39.  
  40.     if (deportista){
  41.         callback(null, deportista);
  42.     } else {
  43.         callback(`No existe el deportista con el ID ${id}, sorry`);
  44.     }
  45. }
  46.  
  47. // DEFINICIÓN DE LA FUNCIÓN GETDEPORTE
  48. const getDeporte =  (id, callback) => {
  49.     const  deporte = deportes.find( d => d.id === id)?.deporte;
  50.  
  51.     if (deporte){
  52.         callback(null, deporte);
  53.     } else {
  54.         callback(`No existe el deporte con el ID ${id}, sorry`);
  55.     }
  56. }
  57.  
  58. const id = 4;
  59.  
  60. // INVOCACIÓN
  61. getDeportista(id, (err, deportistaCB) => {
  62.  
  63.         if (err) {
  64.             console.log("Error!!!");
  65.             return console.log(err);
  66.         }
  67.  
  68.         getDeporte(id, (err, deporteCB) => {
  69.  
  70.             if(err) {
  71.                 console.log("Error!!!");
  72.                 return console.log(err);
  73.             }
  74.          
  75.             console.log(`El deportista ${deportistaCB} practica ${deporteCB}`);
  76.         }
  77.         )
  78.     }
  79. );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement