Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input) {
- for (let i = 0; i < input.length; i++) {
- let movies = {};
- let command = input[i].split(" ");
- if (command[0] === 'addMovie') {
- command.shift();
- command = command.join(" ");
- if (!movies.hasOwnProperty(command)) {
- movies.name = command;
- }
- for (let j = 1; j < input.length; j++) {
- let secondCommand = input[j].split(' ');
- secondCommand = secondCommand.join(' ');
- if (secondCommand.includes(command) && secondCommand.includes('onDate')) {
- secondCommand = secondCommand.split('onDate ');
- movies.date = secondCommand[1];
- } else if (secondCommand.includes(command) && secondCommand.includes('directedBy')) {
- secondCommand = secondCommand.split('directedBy ');
- movies.director = secondCommand[1];
- }
- }
- }
- if(movies.hasOwnProperty('name') && movies.hasOwnProperty('date') && movies.hasOwnProperty('director'))
- {
- console.log(JSON.stringify(movies));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement