Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function movies(array) {
- let movieArr = [];
- while (array.length > 0) {
- let movie = array.shift()
- if (movie.includes('addMovie ')) {
- // let command = movie.shift();
- movieName = movie.split('addMovie ')[1]
- // movieObj.name = movie;
- let movieObj = {
- name: movieName,
- // date: undefined,
- // director: undefined,
- };
- movieArr.push(movieObj);
- }
- if (movie.includes(` onDate `)) {
- let result = movie.split(` onDate `);
- let found = movieArr.find(el => el.name === result[0])
- if (found) {
- found.date = result[1];
- }
- // if (movieArr.includes(result[0])) {
- // movieObj.date = result[1];
- // }
- }
- if (movie.includes(` directedBy `)) {
- let result = movie.split(` directedBy `);
- let found = movieArr.find(el => el.name === result[0])
- if (found){
- found.director = result[1];
- }
- // if (movieArr.includes(result[0])) {
- // movieObj.director = result[1];
- // }
- }
- }
- movieArr.forEach(found=>{
- if(found.name && found.date && found.director){
- console.log(JSON.stringify(found))
- }
- })
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement