Advertisement
bebo231312312321

Untitled

Feb 28th, 2023
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function movies(array) {
  2.     let movieArr = [];
  3.     while (array.length > 0) {
  4.         let movie = array.shift()
  5.         if (movie.includes('addMovie ')) {
  6.           //  let command = movie.shift();
  7.             movieName = movie.split('addMovie ')[1]
  8.            // movieObj.name = movie;
  9.             let movieObj = {
  10.                 name: movieName,
  11.                // date: undefined,
  12.                // director: undefined,
  13.             };
  14.             movieArr.push(movieObj);
  15.         }
  16.         if (movie.includes(` onDate `)) {
  17.             let result = movie.split(` onDate `);
  18.             let found = movieArr.find(el => el.name === result[0])
  19.             if (found) {
  20.            found.date = result[1];
  21.             }
  22.             // if (movieArr.includes(result[0])) {
  23.             //     movieObj.date = result[1];
  24.             // }
  25.         }
  26.  
  27.         if (movie.includes(` directedBy `)) {
  28.             let result = movie.split(` directedBy `);
  29.             let found = movieArr.find(el => el.name === result[0])
  30.             if (found){
  31.             found.director = result[1];
  32.             }
  33.  
  34.             // if (movieArr.includes(result[0])) {
  35.             //     movieObj.director = result[1];
  36.                
  37.             // }
  38.         }
  39.        
  40.     }
  41.     movieArr.forEach(found=>{
  42.         if(found.name && found.date && found.director){
  43.             console.log(JSON.stringify(found))
  44.         }
  45.     })
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement