Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input) {
- let initial = input
- .shift()
- .split(', ');
- let partisipants = {};
- initial.forEach(curr => {
- partisipants[curr] = 0;
- });
- let namePattern = /[a - zA - Z]/g;
- let distPattern = /\d/g;
- let racers = input.slice(0, input.indexOf('end of race'))
- .forEach(line => {
- let name = line.match(namePattern).join('');
- let distance = line.match(distPattern).map(Number).reduce((a, c) => a + c);
- if (partisipants.hasOwnProperty(name)){
- partisipants[name] += distance;
- }
- })
- let output = Object.entries(partisipants).sort((a,b) => b[1] - a[1]);
- console.log(`1st place: ${output[0][0]}
- 2nd place: ${output[1][0]}
- 3rd place: ${output[2][0]}`);
- };
- solve('George, Peter, Bill, Tom',
- 'G4e@55or%6g6!68e!!@',
- 'R1@!3a$y4456@',
- 'B5@i@#123ll',
- 'G@e54o$r6ge#',
- '7P%et^#e5346r',
- 'T$o553m&6',
- 'end of race'
- );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement