Advertisement
SvilenVelikov

Untitled

Sep 22nd, 2021
962
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(input = []) {
  2.     let movies = [];
  3.     while (input.length > 0) {
  4.         let line = input.shift();
  5.         let tokens = line.split(" ");
  6.         if (tokens.includes('addMovie')) {
  7.             tokens.shift();
  8.             let movieName = tokens.join(" ");
  9.             let movie = { name: movieName };
  10.             movies.push(movie);
  11.         } else if (tokens.includes('directedBy')) {
  12.             let index = tokens.indexOf('directedBy');
  13.             let movieName = tokens.slice(0, index).join(" ");
  14.             let movieDirector = tokens.slice(index +1, tokens.length).join(" ");
  15.             for (let mv of movies) {
  16.                 if (mv.name === movieName) {
  17.                     mv['director'] = movieDirector;
  18.                 }
  19.             }
  20.  
  21.  
  22.         } else if (tokens.includes('onDate')) {
  23.  
  24.         }
  25.     }
  26.  
  27.     return movies;
  28. }
  29.  
  30. console.log(solve(
  31.     [
  32.         'addMovie Fast and Furious',
  33.         'addMovie Godfather',
  34.         'Inception directedBy Christopher Nolan',
  35.         'Godfather directedBy Francis Ford Coppola',
  36.         'Godfather onDate 29.07.2018',
  37.         'Fast and Furious onDate 30.07.2018',
  38.         'Batman onDate 01.08.2018',
  39.         'Fast and Furious directedBy Rob Cohen'
  40.     ]
  41. ));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement