Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input){
- let band = {};
- let bandCount = {};
- let totalTime = 0;
- let group = input.pop();
- let arr = [];
- let set = new Set();
- for(let line of input){
- if(line === 'start of concert'){
- break;
- }
- let [addOrPlay, bandName, timeOrSingers] = line.split('; ');
- if(addOrPlay === 'Add'){
- arr = timeOrSingers.split(', ');
- for(let i = 0; i < arr.length; i++){
- if(!band.hasOwnProperty(bandName)){
- band[bandName] = [arr[i]];
- }else if(band.hasOwnProperty(bandName)){
- band[bandName].push(arr[i]);
- }
- }
- }else if(addOrPlay === 'Play'){
- if(!bandCount.hasOwnProperty(bandName)){
- bandCount[bandName] = +(timeOrSingers);
- totalTime += +(timeOrSingers);
- }else{
- bandCount[bandName] += +(timeOrSingers);
- totalTime += +(timeOrSingers);
- }
- }
- }
- let arrayBandCount = Object.entries(bandCount);
- arrayBandCount.sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0]));
- console.log(`Total time: ${totalTime}`);
- for(let item of arrayBandCount){
- console.log(`${item[0]} -> ${item[1]}`);
- }
- let result = Object.entries(band);
- console.log(group);
- for(let j = 0; j < result.length; j++){
- for(let i = 0; i < result[j][1].length; i++){
- if(result[j][1][i] === result[0][1][i+1]){
- let index = result[j][1].indexOf(result[j][1][i+1]);
- result[j][1].splice(index, 1);
- }
- }
- if(result[j][0] === group){
- for(let boy of result[j][1]){
- set.add(boy);
- }
- }
- }
- let arrResult = Array.from(set);
- console.log(`=> ${arrResult.join('\n=> ')}`);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement