Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function cookingFactory(input) {
- let currentItem = input.shift().split('#');
- let output = [];
- let bestBatchQuallity = -1001;
- let avaregaQualityOfBestBatchQuallity = 0
- let minLength = 0;
- while (currentItem[0] !== 'Bake It!') {
- currentItem = currentItem.map(x=>parseInt(x));
- let currentBatchQuallity = 0;
- for (let i = 0; i < currentItem.length; i++) {
- currentBatchQuallity += currentItem[i];
- }
- let currentAverageQuality = currentBatchQuallity / (currentItem.length);
- let currentLength = currentItem.length;
- if (currentBatchQuallity > bestBatchQuallity) {
- output = currentItem;
- bestBatchQuallity = currentBatchQuallity;
- avaregaQualityOfBestBatchQuallity = currentAverageQuality;
- minLength = currentLength;
- } else if (currentBatchQuallity === bestBatchQuallity) {
- if (currentAverageQuality > avaregaQualityOfBestBatchQuallity) {
- output = currentItem;
- bestBatchQuallity = currentBatchQuallity;
- avaregaQualityOfBestBatchQuallity = currentAverageQuality;
- minLength = currentLength;
- } else if (currentAverageQuality === avaregaQualityOfBestBatchQuallity) {
- if (currentLength < minLength) {
- output = currentItem;
- bestBatchQuallity = currentBatchQuallity;
- avaregaQualityOfBestBatchQuallity = currentAverageQuality;
- minLength = currentLength;
- }
- }
- }
- currentItem = input.shift().split('#');
- }
- console.log(`Best Batch quality: ${bestBatchQuallity}`);
- console.log(output.join(' '));
- }
Advertisement
Add Comment
Please, Sign In to add comment