Advertisement
nikolayneykov

Untitled

Mar 7th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function CookingFactory(input) {
  2.     input.pop();
  3.     let totalQuality = 0;
  4.     let bestBatch = [];
  5.  
  6.     for (const batches of input) {
  7.         input[input.indexOf(batches)] = batches.split('#').map(Number);
  8.     }
  9.  
  10.     input.sort(function (a, b) {
  11.         let result = b.reduce((a, b) => a + b) - a.reduce((a, b) => a + b);
  12.  
  13.         if (result === 0) {
  14.             result = b.reduce((a, b) => a + b) / b.length - a.reduce((a, b) => a + b) / a.length;
  15.         }
  16.  
  17.         if (result === 0) {
  18.             result = a.length - b.length;
  19.         }
  20.  
  21.         return result;
  22.     });
  23.  
  24.     console.log(`Best Batch quality: ${input[0].reduce((a, b) => a + b)}`);
  25.     console.log(input[0].join(' '));
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement