Ivankooo1

Concert - try

Mar 24th, 2020
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. function concert(param){
  2. let obj = {};
  3.  
  4. for(let el of param){
  5. if(el === 'start of concert'){
  6. break;
  7. }
  8. let [command,bandName,memberName] = el.split('; ');
  9.  
  10. if(command === 'Play'){
  11. let time = +memberName;
  12.  
  13. if(!obj[bandName]){
  14. obj[bandName] = {time};
  15. }else{
  16. obj[bandName].time += time;
  17. }
  18.  
  19.  
  20. }else if(command === 'Add'){
  21. let bandMembers = memberName.split(', ');
  22. let sortedBandMembers = sortMembers(bandMembers);
  23.  
  24. if(!obj[bandName]){
  25. obj[bandName] = {};
  26. obj[bandName] = {sortedBandMembers};//tuk se dobavqt 4lenovete na bandata i se zapazva time ako go ima
  27. }else{
  28. obj[bandName] = {sortedBandMembers};//tuk ako ima nov 4ovek v banda se dobava kum ostanallite
  29. }
  30. }
  31. }
  32. function sortMembers(arr){
  33. return arr.filter((el,ind)=> arr.indexOf(el) === ind)
  34. }
  35. }
  36. concert([
  37.  
  38. 'Play; The Beatles; 2000',
  39. 'Add; The Beatles; John Lennon, Paul McCartney, George Harrison, Ringo Starr',
  40. 'Add; The Beatles; Ivan, John Lennon, Paul McCartney, George Harrison, Ringo Starr',
  41. 'Add; Eagles; Glenn Frey, Don Henley, Bernie Leadon, Randy Meisner',
  42. 'Play; Eagles; 1869',
  43. 'Add; The Rolling Stones; Brian Jones, Mick Jagger, Keith Richards',
  44. 'Add; The Rolling Stones; Brian Jones, Mick Jagger, Keith Richards, Bill Wyman, Charlie Watts, Ian Stewart',
  45. 'Play; The Rolling Stones; 4239',
  46. 'start of concert',
  47. 'The Rolling Stones'
  48. ]
  49. );
Advertisement
Add Comment
Please, Sign In to add comment