Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function CookingFactory(input) {
- input.pop();
- let totalQuality = 0;
- let bestBatch = [];
- for (const batches of input) {
- input[input.indexOf(batches)] = batches.split('#').map(Number);
- }
- input.sort(function (a, b) {
- let result = b.reduce((a, b) => a + b) - a.reduce((a, b) => a + b);
- if (result === 0) {
- result = b.reduce((a, b) => a + b) / b.length - a.reduce((a, b) => a + b) / a.length;
- }
- if (result === 0) {
- result = a.length - b.length;
- }
- return result;
- });
- console.log(`Best Batch quality: ${input[0].reduce((a, b) => a + b)}`);
- console.log(input[0].join(' '));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement