nikolayneykov

Untitled

Mar 2nd, 2019
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(params) {
  2.     let batches = [];
  3.     for (let p of params) {
  4.         if (p === 'Bake It!') {
  5.             break;
  6.         }
  7.         let currentBatch = p.split('#').filter(x => x !== '').map(Number);
  8.         batches.push(currentBatch);
  9.     }
  10.     batches.sort(function (a, b) {
  11.         let aSum = a.reduce((c, d) => c + d, 0);
  12.         let bSum = b.reduce((c, d) => c + d, 0);
  13.         let result = bSum - aSum;
  14.         if (result === 0) {
  15.             result = (bSum / b.length) - (aSum / a.length);
  16.             if (result === 0) {
  17.                 result = a.length - b.length;
  18.             }
  19.         }
  20.         return result;
  21.     });
  22.     let bestBatch = batches[0];
  23.     let quality = bestBatch.reduce((a, b) => a + b, 0);
  24.     console.log(`Best Batch quality: ${quality}\n${bestBatch.join(' ')}`)
  25. }
Advertisement
Add Comment
Please, Sign In to add comment