Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(array) {
- let movies = [];
- array.forEach(el => {
- let line = el.split(' ');
- if (line.includes('addMovie')) {
- let movie = line.slice(1).join(' ');
- movies.push({
- name: movie
- });
- } else if (line.includes('directedBy')) {
- let index = line.indexOf('directedBy');
- let movieName = line.slice(0, index).join(' ');
- let movieDirector = line.slice(index + 1).join(' ');
- let movie = movies.find(m => m.name === movieName);
- if (movie) {
- movie.director = movieDirector;
- }
- } else if (line.includes('onDate')) {
- let index = line.indexOf('onDate');
- let movieName = line.slice(0, index).join(' ');
- let movieDate = line.slice(index + 1).join(' ');
- let movie = movies.find(m => m.name === movieName);
- if (movie) {
- movie.date = movieDate;
- }
- }
- });
- console.log(movies);
- for (const el of movies) {
- let keys = Object.keys(el);
- if (keys.length === 3) {
- console.log(JSON.stringify(el));
- }
- }
- }
Add Comment
Please, Sign In to add comment