Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. function solve(input) {
  2.  
  3.  
  4.  
  5. for (let i = 0; i < input.length; i++) {
  6.  
  7. let movies = {};
  8. let command = input[i].split(" ");
  9.  
  10. if (command[0] === 'addMovie') {
  11. command.shift();
  12. command = command.join(" ");
  13.  
  14. if (!movies.hasOwnProperty(command)) {
  15. movies.name = command;
  16. }
  17.  
  18. for (let j = 1; j < input.length; j++) {
  19.  
  20. let secondCommand = input[j].split(' ');
  21. secondCommand = secondCommand.join(' ');
  22.  
  23. if (secondCommand.includes(command) && secondCommand.includes('onDate')) {
  24. secondCommand = secondCommand.split('onDate ');
  25. movies.date = secondCommand[1];
  26. } else if (secondCommand.includes(command) && secondCommand.includes('directedBy')) {
  27. secondCommand = secondCommand.split('directedBy ');
  28. movies.director = secondCommand[1];
  29. }
  30.  
  31.  
  32. }
  33.  
  34.  
  35. }
  36.  
  37. if(movies.hasOwnProperty('name') && movies.hasOwnProperty('date') && movies.hasOwnProperty('director'))
  38. {
  39. console.log(JSON.stringify(movies));
  40. }
  41.  
  42. }
  43.  
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement